I am trying to run a For Each loop using the following chunk:
It seems to be executing nicely, but at the Next ws line the code doesn't jump to the next worksheet in the workbook COM. How is it not catching this line and jumping to the next worksheet in the workbook?
Code:
Set COM = Workbooks("COMM_COMBINED.xls")
Code:
For Each ws In COM.Worksheets
AC = ws.Name
Do While COM.Worksheets(AC).Cells(j, 1) <> ""
Set COMVAR = COM.Worksheets(AC).Cells(j, 1)
z = 5
Do While MAIN.Worksheets("M_" & AC).Cells(z, 1) <> ""
Set MAINVAR = MAIN.Worksheets("M_" & AC).Cells(z, 1)
If MAINVAR = COMVAR Then
MAIN.Worksheets("M_" & AC).Range(MAINVAR, MAINVAR.End(xlToRight)).Copy
COM.Worksheets(AC).Activate
Cells(j, 1).Select
Selection.End(xlToRight).Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
z = z + 1
Loop
j = j + 1
Loop
Next ws
It seems to be executing nicely, but at the Next ws line the code doesn't jump to the next worksheet in the workbook COM. How is it not catching this line and jumping to the next worksheet in the workbook?