Robert E Lee
Active Member
- Joined
- Aug 10, 2005
- Messages
- 266
I have the following code which works perfectly. What I now wish to do is loop through all worksheet sin Wb except sheet1. I have tried to use a For Each Loop and an If statement trying to exclude Sheet1 but it wil not compile with the message that I have a next without a for. I have tried many permutations without success.Aany help appreciated
Many thanks with apologies for forgetting the code tags
Rob
Code:
Wb.Sheets("Sheet2").Select
R = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
BudgetCode = Wb.Sheets("Sheet2").Range("A2")
Wb2.Activate
Range("D2").Select
R1 = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
Set TargetRange = Range(ActiveCell, ActiveCell.Offset(R, 0))
For Each c In TargetRange
If c = BudgetCode Then
Set SelectRange = Range(c.Offset(0, -2), (c.Offset(0, 3)))
SelectRange.Copy Destination:=Wb.Sheets("Sheet2").Range("A" & R)
R = R + 1
End If
Next c
End Sub
Many thanks with apologies for forgetting the code tags
Rob
Last edited by a moderator: