surlybiker
New Member
- Joined
- Jul 1, 2011
- Messages
- 14
In a sample spreadsheet, beginning at row 5, I need to clear the contents of the range E:K if either cell in column G or J is blank or contains a zero.
The following code works, but it is extremely slowly (about a second per row in the actual spreadsheet which contains up to 4000 rows of data across hundreds of columns):
Sub clear_ranges()
Dim ws As Worksheet
Dim x As Integer
Set ws = ThisWorkbook.Sheets("Sheet1")
For x = 5 To ws.Range("A" & Rows.Count).End(xlUp).Row
If (ws.Range("G" & x).Value = 0 Or ws.Range("G" & x).Value = "") And (ws.Range("J" & x).Value = 0 Or ws.Range("J" & x).Value = "") Then
ws.Range("E" & x & ":" & "K" & x).Clear
End If
Next x
End Sub
Is there a more efficient way to perform this task?
Thanks so much!
The following code works, but it is extremely slowly (about a second per row in the actual spreadsheet which contains up to 4000 rows of data across hundreds of columns):
Sub clear_ranges()
Dim ws As Worksheet
Dim x As Integer
Set ws = ThisWorkbook.Sheets("Sheet1")
For x = 5 To ws.Range("A" & Rows.Count).End(xlUp).Row
If (ws.Range("G" & x).Value = 0 Or ws.Range("G" & x).Value = "") And (ws.Range("J" & x).Value = 0 Or ws.Range("J" & x).Value = "") Then
ws.Range("E" & x & ":" & "K" & x).Clear
End If
Next x
End Sub
Is there a more efficient way to perform this task?
Thanks so much!