Hi All. Pls help me. What's wrong in the following code? The line in red in returns error. But why? Both files i keep open during running macro.
------------------------------------
Sub GL_DPR_FillIn()
' Fills in Report with up-to-date data.
Dim wbA As Workbook
Dim wbB As Workbook
Dim wsName, lastRow
Dim j
Set wbA = Workbooks("GL Rates Calculation.xlsm") 'This one should already be open
Set wbB = Workbooks("DPR_ALS.xlsx")
For j = 5 To 18 Step 1
wbA.Sheets("GL").Range("AG" & "j" & ":" & "AN" & "j").Copy
If j = 5 Then wsName = "Ch22"
If j = 6 Then wsName = "Ch24"
If j = 7 Then wsName = "Ch30"
If j = 8 Then wsName = "Ch54"
If j = 9 Then wsName = "Ch56"
If j = 10 Then wsName = "Ch60"
If j = 11 Then wsName = "Ch62"
If j = 12 Then wsName = "Ch65"
If j = 13 Then wsName = "Ch67"
If j = 14 Then wsName = "Ch115b"
If j = 15 Then wsName = "Ch117"
If j = 16 Then wsName = "Ch123"
If j = 17 Then wsName = "Ch51"
If j = 18 Then wsName = "Ch124"
lastRow = Sheets(wsName).Cells(Rows.Count, "C").End(xlUp).Row
Sheets(wsName).Range("C" & lastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Next j
End Sub
------------------------------------
Sub GL_DPR_FillIn()
' Fills in Report with up-to-date data.
Dim wbA As Workbook
Dim wbB As Workbook
Dim wsName, lastRow
Dim j
Set wbA = Workbooks("GL Rates Calculation.xlsm") 'This one should already be open
Set wbB = Workbooks("DPR_ALS.xlsx")
For j = 5 To 18 Step 1
wbA.Sheets("GL").Range("AG" & "j" & ":" & "AN" & "j").Copy
If j = 5 Then wsName = "Ch22"
If j = 6 Then wsName = "Ch24"
If j = 7 Then wsName = "Ch30"
If j = 8 Then wsName = "Ch54"
If j = 9 Then wsName = "Ch56"
If j = 10 Then wsName = "Ch60"
If j = 11 Then wsName = "Ch62"
If j = 12 Then wsName = "Ch65"
If j = 13 Then wsName = "Ch67"
If j = 14 Then wsName = "Ch115b"
If j = 15 Then wsName = "Ch117"
If j = 16 Then wsName = "Ch123"
If j = 17 Then wsName = "Ch51"
If j = 18 Then wsName = "Ch124"
lastRow = Sheets(wsName).Cells(Rows.Count, "C").End(xlUp).Row
Sheets(wsName).Range("C" & lastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Next j
End Sub