0

I have two tables. First is a list of rows where user needs to put comment in proper column. Second is database.

If user inserts anything to comment column then that row is copied to another sheet (database).

My code works good until user inserts comment in last row user table. Then he gets error message: "Method ShowAllData of object '_Worksheet' failed.

In fact row is copied to another sheet but the table in another sheet increases its range to hundred thousands of empty lines.

Below you can see my code. Please, advise me what can I fix here.

Dim ws1 As Worksheet
Dim ws2 As Worksheet

Set ws1 = Worksheets("Comments_database")
Set ws2 = Worksheets("PO'sDailyMonitor")

Application.ScreenUpdating = False

Worksheets("PO'sDailyMonitor").Range("P9").AutoFilter Field:=16, Criteria1:="<>"
ws2.Range("A10:Q10", Selection.End(xlDown)).SpecialCells(xlCellTypeVisible).Copy
ws1.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

Application.CutCopyMode = False

ws2.ShowAllData
ws2.Range("P10:P10000").ClearContents

Application.ScreenUpdating = True

MsgBox ("Database updated")

1 Answer 1

0

I solved it.

Just replaced this:

ws2.Range("A10:Q10", Selection.End(xlDown)).SpecialCells(xlCellTypeVisible).Copy

with:

ws2.ListObjects("PO_Query4").ListColumns(1).DataBodyRange.Resize(, 17).Select

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.