danelskibr
Board Regular
- Joined
- Dec 31, 2014
- Messages
- 58
Hello,
I am trying to run a loop through all of the worksheets in my workbook. I have around 100 sheets in the workbook, but they are each are formatted one of only two ways. For test purposes only, I have the macro putting either a "1" or a "2" in cell A1 depending on which type of sheet it is (if K3 is blank).
I found the following code on Microsoft's website and modified it slightly for my use. The macro works, but it will only run for the active worksheet and stop. Basically, it is not looping.
Thank you in advance for the help!
I am trying to run a loop through all of the worksheets in my workbook. I have around 100 sheets in the workbook, but they are each are formatted one of only two ways. For test purposes only, I have the macro putting either a "1" or a "2" in cell A1 depending on which type of sheet it is (if K3 is blank).
I found the following code on Microsoft's website and modified it slightly for my use. The macro works, but it will only run for the active worksheet and stop. Basically, it is not looping.
Code:
Sub Format()
Dim WS_Count As Integer
Dim I As Integer
' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For I = 1 To WS_Count
If IsEmpty(Range("K3").Value) = True Then
Range("A1").Select
ActiveCell.FormulaR1C1 = "1"
Else
Range("A1").Select
ActiveCell.FormulaR1C1 = "2"
End If
Next I
End Sub
Thank you in advance for the help!