Kemidan2014
Board Regular
- Joined
- Apr 4, 2022
- Messages
- 229
- Office Version
- 365
- Platform
- Windows
With help from this community ive managed to scrap together bits of code to try and use copy pasting as a form of "updating" a master sheet in our tracking excel database where all the data is being referenced from a file we download weekly from our customers website that we save in the same location with the same name.
This code which i used to copy WITH IN the same work book from Sheet to Sheet that i got from you fine folks works perfectly
What I tried to do was copy and change this code to target different WORKBOOK and copy and paste specific columns and filtered rows to paste new information at the bottom of a the target worksheet but
I get a runtime error -2147352565 (80020000b) No cells were found. on the line "Set srcWB...." what am i doing wrong or including in this line for it to Error? See code below
This code which i used to copy WITH IN the same work book from Sheet to Sheet that i got from you fine folks works perfectly
VBA Code:
Sub Filter_Data()
Application.ScreenUpdating = False
Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet
Set srcWS = Sheets("Sheet1")
Set desWS = Sheets("Sheet2")
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
desWS.UsedRange.Offset(1).ClearContents
With srcWS
.Range("W2:W" & LastRow).Formula = "=IF(AND(D2=""0101-6"",G2<>""Closed-Cancelled"",G2<>""Closed - LTCM Effective"",G2<>""Closed - LTCM Ineffective"",G2<>""Closed-No Response Required"",G2<>""#N/A""),""true"",""false"")"
.Cells(1).CurrentRegion.AutoFilter 23, "true"
.Range("A2:V" & LastRow).SpecialCells(xlCellTypeVisible).Copy
With desWS
.Cells(.Rows.count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
.Columns.AutoFit
End With
.Range("A1").AutoFilter
.Columns("W").Delete
End With
Application.ScreenUpdating = True
End Sub
What I tried to do was copy and change this code to target different WORKBOOK and copy and paste specific columns and filtered rows to paste new information at the bottom of a the target worksheet but
I get a runtime error -2147352565 (80020000b) No cells were found. on the line "Set srcWB...." what am i doing wrong or including in this line for it to Error? See code below
Code:
Sub Update_trial()
Application.ScreenUpdating = False
Dim LastRow As Long, srcWB As Workbook, desWB As Workbook
Workbooks.Open ("O:\1_All Customers\Current Complaints\ToyotaData.xlsx")
Set srcWB = Workbooks("O:\1_All Customers\Current Complaints\ToyotaData.xlsx").Worksheets("Data")
Set desWB = Workbooks("Customer Database Test 2.xlsm").Worksheets("sheet1")
LastRow = srcWB.Cells.Find("Q*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With srcWB
.Range("AN2:AN" & LastRow).Formula = "=IF(MATCH(A2,'[Customer database test 2.xlsm]Sheet1'!$A$2),""true"",""false"")"
.Cells(1).CurrentRegion.AutoFilter 23, "false"
.Range("A:B,D:D,E:E,H:K,O:O,Q:AB,AH:AH" & LastRow).SpecialCells(xlCellTypeVisible).Copy
With desWB
.Cells(.Rows.count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
.Columns.AutoFit
End With
.Range("A1").AutoFilter
.Columns("W").Delete
End With
Application.ScreenUpdating = True
End Sub