Trying2learnVBA
Board Regular
- Joined
- Aug 21, 2019
- Messages
- 67
- Office Version
- 365
- 2021
- Platform
- 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
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