What's wrong with my VBA Code

Trying2learnVBA

Board Regular
Joined
Aug 21, 2019
Messages
67
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

I am trying to fill out WB2 with data from WB1 which houses the macro - the code runs but nothing gets filled out.

Dim WB1 As Workbook -
Dim WB2 As Workbook
Dim LastRow As Long

Application.ScreenUpdating = False

Set WB1 = ActiveWorkbook
Set WB2 = Workbooks.Open(Environ("USERPROFILE") & "\Desktop\N_Invoices\Quadrate Templates\extKO01.xlsx")

With WB2.Sheets("KO01_IO")
LastRow = .Range("A:AW").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If LastRow > 3 Then
.Range("A4:AW" & LastRow).ClearContents
End If
End With
This works - I simply want WB2 to not have any unwanted data.

With WB1.Sheets("N_Invoices")
'Find the last cell's row with data in any column
LastRow = .Range("A:AW").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Could use .Cells(.Rows.Count, 1).End(xlUp).Row
'Copy the values
WB2.Sheets("KO01_IO").Range("A4" & LastRow) = .Range("V6" & LastRow).Value
End With
WB2.Save

Nothing happens here - WB2 should have column A filled out with everything in WB1 colum V6 to last row.

End Sub

I am not getting any error here - so I am not sure if I have anything backwards.

Thank you
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,215,655
Messages
6,126,053
Members
449,283
Latest member
GeisonGDC

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