mwhite1998
New Member
- Joined
- Nov 21, 2023
- Messages
- 3
- Office Version
- 365
Hello,
I am looking to create a loop to run through all the worksheets in my workbook to run some code that clears the contents of "blank cells".
The code works for the active worksheet but doesn't seem to run through the loop to the next one.
Thanks for any help
Matt
I am looking to create a loop to run through all the worksheets in my workbook to run some code that clears the contents of "blank cells".
The code works for the active worksheet but doesn't seem to run through the loop to the next one.
VBA Code:
Sub WorksheetLoop()
Dim ws As Worksheet
For Each ws In Worksheets
Call RemoveBlanks
Next
End Sub
Sub RemoveBlanks()
columnNumber = 1
Do Until columnNumber > 26
rowNumber = 2
columnLetter = Chr(columnNumber + 64)
lastRow = Range(columnLetter & rows.Count).End(xlUp).Row
Do Until rowNumber > lastRow
If Range(columnLetter & rowNumber).Value = "" Then
Range(columnLetter & rowNumber).ClearContents
End If
rowNumber = rowNumber + 1
Loop
columnNumber = columnNumber + 1
Loop
End Sub
Thanks for any help
Matt