Dear Expert Out there,
I have created the macro below to copy the value to another sheet if the description is closing balance.
However I run into error "object variable or with block variable not set". What does it mean. Can help me on this.
[Dim lr As Long, r As Long
Dim ws As Worksheet
Dim wk As Worksheet
Dim wsName As String
Dim wkDest As String
wsName = Sheets("Instruction").Range("H4")
wkDest = Sheets("Instruction").Range("H6")
On Error Resume Next
Set ws = Sheets(wsName)
Set wk = Sheets(wkDest)
On Error GoTo 0
If ws Is Nothing Then
MsgBox wsName & " is not a valid sheet name for this workbook"
Else
With ws
lr = .Cells(.Rows.Count, "B").End(xlUp).Row
For r = lr To 1 Step -1
' Classify - REPATRIATION
If ws.Range("B" & r) Like "*CLOSING BALANCE*" Then
ws.Range("E" & r).Copy Destination:=wk.Range("E" & 4)
End If
Next r
End With
End If]
I have created the macro below to copy the value to another sheet if the description is closing balance.
However I run into error "object variable or with block variable not set". What does it mean. Can help me on this.
[Dim lr As Long, r As Long
Dim ws As Worksheet
Dim wk As Worksheet
Dim wsName As String
Dim wkDest As String
wsName = Sheets("Instruction").Range("H4")
wkDest = Sheets("Instruction").Range("H6")
On Error Resume Next
Set ws = Sheets(wsName)
Set wk = Sheets(wkDest)
On Error GoTo 0
If ws Is Nothing Then
MsgBox wsName & " is not a valid sheet name for this workbook"
Else
With ws
lr = .Cells(.Rows.Count, "B").End(xlUp).Row
For r = lr To 1 Step -1
' Classify - REPATRIATION
If ws.Range("B" & r) Like "*CLOSING BALANCE*" Then
ws.Range("E" & r).Copy Destination:=wk.Range("E" & 4)
End If
Next r
End With
End If]