Copy paste macro that cant find cells?

Kemidan2014

Board Regular
Joined
Apr 4, 2022
Messages
226
Office Version
  1. 365
Platform
  1. 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
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,437
Messages
6,124,871
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top