orangehenry
New Member
- Joined
- Oct 26, 2015
- Messages
- 7
Hi,
I have a vba script that is clearing the contents of all cells that meet a certain formatting condition (ColourIndex). It does this by cycling through all worksheets and looking at the ActiveSheet.UsedRange
However, I am finding that this is missing random cells in my worksheets. I understand that UsedRange can be a bit buggy but I'm unclear how to integrate some of the workarounds I've seen on the forum into my script.
Can anyone suggest the fix so that my script won't miss cells in my workbook?
I have a vba script that is clearing the contents of all cells that meet a certain formatting condition (ColourIndex). It does this by cycling through all worksheets and looking at the ActiveSheet.UsedRange
However, I am finding that this is missing random cells in my worksheets. I understand that UsedRange can be a bit buggy but I'm unclear how to integrate some of the workarounds I've seen on the forum into my script.
Can anyone suggest the fix so that my script won't miss cells in my workbook?
SQL:
Private Sub CommandButton1_Click()
'Updateby Extendoffice
Dim rngCl As range
Dim xRows As Long
Dim xCol As Long
Dim colorLg As Long
Dim ws As Worksheet, a As range
colorLg = 40
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
With ActiveSheet.UsedRange
For xRows = .Rows.Count To 1 Step -1
For xCol = 1 To .Columns.Count
If .Cells(xRows, xCol).Interior.ColorIndex = colorLg Then
.Cells(xRows, xCol).ClearContents
Exit For
End If
Next xCol
Next xRows
End With
Next
Sheets("Detailed Stock Schedule").range("A4:C400").ClearContents
Sheets("Detailed Stock Schedule").range("E4:J400").ClearContents
Sheets("Detailed Stock Schedule").range("L4:O400").ClearContents
Application.ScreenUpdating = True
Unload UserForm2
End Sub