Oberon70
Board Regular
- Joined
- Jan 21, 2022
- Messages
- 160
- Office Version
- 365
- Platform
- Windows
Hi,
I have the below code, which for some reason gives me the result of $A$1 instead of $AK$28, which is the last cell for the current statement I am testing with.
It will work if I change the code to the below, but was wondering why I have to activate the sheet for it to work? Is there a way when I call the function it is pointing to the worksheet I want?
I have the below code, which for some reason gives me the result of $A$1 instead of $AK$28, which is the last cell for the current statement I am testing with.
VBA Code:
Sub CopyTbleToTmpSht()
Dim LastCell As String
Dim oarray As Variant
With wsData
LastCell = wsData.Range(FindLast(3)).Address
End With
oarray = wsData.Range("A1:" & LastCell)
wsTmpData.Range("A1:" & LastCell) = oarray
Debug.Print LastCell
'wsData.Range("A1:" & LastCell).Select
End Sub
It will work if I change the code to the below, but was wondering why I have to activate the sheet for it to work? Is there a way when I call the function it is pointing to the worksheet I want?
VBA Code:
Sub CopyTbleToTmpSht()
Dim LastCell As String
Dim oarray As Variant
With wsData
.Activate
LastCell = wsData.Range(FindLast(3)).Address
End With
oarray = wsData.Range("A1:" & LastCell)
wsTmpData.Range("A1:" & LastCell) = oarray
Debug.Print LastCell
'wsData.Range("A1:" & LastCell).Select
End Sub