most
Board Regular
- Joined
- Feb 22, 2011
- Messages
- 107
- Office Version
- 365
- 2019
- Platform
- Windows
- Mobile
Going crazy on this one, what i'm doing wrong?
It's an "Object variable or With block variable not set" on "Set FromWbs" in the function.
/Marcus
It's an "Object variable or With block variable not set" on "Set FromWbs" in the function.
/Marcus
Code:
Public FromWorkbook As Workbook
Public ToWorkbook As Workbook
Public FromStartRow As Integer
Public ToStartRow As Integer
Sub CopyColumn2Column()
' Use of copy column function
'
Dim FromWorkbook As Workbook, ToWorkbook As Workbook
'Global parameters
Set FromWorkbook = Workbooks("Book1")
Set ToWorkbook = Workbooks("Book2")
FromStartRow = 2
ToStartRow = 3
'CopyC2C(Name, FromSheet, FromColumn, ToSheet, ToColumn)
Call CopyC2C("Run 01 - Test", "Sheet2", 1, "Sheet1", 2)
End Sub
Function CopyC2C(Name As String, ByRef FromSheet As String, FromColumn As Integer, ByRef ToSheet As String, ToColumn As Integer)
' Function, Copy column to column between two diffrent sheets
'
Set FromWbs = FromWorkbook.Sheets(FromSheet)
Set ToWbs = ToWorkbook.Sheets(ToSheet)
LastRow = FromWbs.Cells(Rows.count, FromColumn).End(xlUp).Row
Debug.Print "CopyC2C - " & Name & " | " & FromSheet & ", " & FromColumn & " | " & ToSheet & ", " & ToColumn & " | " & LastRow
FromWbs.Range(Cells(FromStartRow, FromColumn), Cells(LastRow, FromColumn)).Copy ToWbs.Cells(ToStartRow, ToColumn)
End Function