B
Brettjg
Hello there, I have some simple code below which counts the sheets and
formulas in a given workbook. The problem is that if I have run the macro
from the last worksheet visible it gives me a formula count of 0, but if run
from the first visible sheet it gives the correct count of 28,119.
How can I make it select the first visible worksheet before it goes into the
"For" routine please? Regards, Brett
Sub aa_count_formulas()
Dim counter, countrow, countcol, countsheet, sh As Worksheet
countsheet = 0
counter = 0
For Each sh In ActiveWorkbook.Worksheets
countcol = 1
Do While countcol <= 78
countrow = 1
Do While countrow <= 1000
If Cells(countrow, countcol).HasFormula = True Then
counter = counter + 1
End If
countrow = countrow + 1
Loop
countcol = countcol + 1
Loop
countsheet = countsheet + 1
NextMsgBox "SHEETS in this workbook: " & countsheet & Chr(13) & Chr(13) &
"FORMULAS in this workbook: " & counter
End Sub
formulas in a given workbook. The problem is that if I have run the macro
from the last worksheet visible it gives me a formula count of 0, but if run
from the first visible sheet it gives the correct count of 28,119.
How can I make it select the first visible worksheet before it goes into the
"For" routine please? Regards, Brett
Sub aa_count_formulas()
Dim counter, countrow, countcol, countsheet, sh As Worksheet
countsheet = 0
counter = 0
For Each sh In ActiveWorkbook.Worksheets
countcol = 1
Do While countcol <= 78
countrow = 1
Do While countrow <= 1000
If Cells(countrow, countcol).HasFormula = True Then
counter = counter + 1
End If
countrow = countrow + 1
Loop
countcol = countcol + 1
Loop
countsheet = countsheet + 1
NextMsgBox "SHEETS in this workbook: " & countsheet & Chr(13) & Chr(13) &
"FORMULAS in this workbook: " & counter
End Sub