I am writing code in VBA for Excel to loop through all the cells in all the worksheets in a workbook and print certain cells based on their numeric value and position. However, I am unable to loop through the cells in a specific worksheet as I get a 424 object required error.
I have tried to debug my code and apparently the problems lies in my nested loop when I try to loop through the entire cells in a specific worksheet.
Public Sub loopThrougSheet()
Dim ws As Worksheet
Dim starting_ws As Worksheet
Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning
Dim cell As Range
Dim data As Range
For Each ws In ThisWorkbook.Worksheets
ws.Activate
Set data = Intersect(ws.UsedRange, ws.Range("A2:AW1048576"))
For Each cell In data
If IsNumeric(cell.Value) And cell.Value > 0.5 Then
Debug.Print (cell.Value)
End If
Next
Next
End Sub
The code does not compile as I get a 424 object required run time error.