Hi guys.
I'm just making my first steps into VBA and I don't know much yet. I've found a VBA online which deletes cells based on the background color and it works perfectly fine, but it could be tweaked a little bit. In my files I always have 4 headers rows and that VBA has no mercy for them :D. I would like to tune that VBA to make it start working from 4th row. Here's the code:
From my research I've realised that I need to change this line
, but I don't know how should I modify it to be honest.
Also I basing to on this VBA I've tried to make another one which will scroll the view to the next color in the given column, but my attempts to do that came to nothing. If someone will have some free time and good will I will really appreciate the help.
Best regards,
Tom.
I'm just making my first steps into VBA and I don't know much yet. I've found a VBA online which deletes cells based on the background color and it works perfectly fine, but it could be tweaked a little bit. In my files I always have 4 headers rows and that VBA has no mercy for them :D. I would like to tune that VBA to make it start working from 4th row. Here's the code:
Excel Formula:
Sub DeleteRowsByColor()
Dim rngCl As Range
Dim xRows As Long
Dim xCol As Long
Dim colorLg As Long
On Error Resume Next
Set rngCl = Application.InputBox _
(Prompt:="Select a cell with the background color to be deleted", _
Title:="Kutools for Excel", Type:=8)
On Error GoTo 0
If rngCl Is Nothing Then
MsgBox "User cancelled operation." & vbCrLf & _
"Processing terminated", vbInformation, "Kutools for Excel"
Exit Sub
End If
colorLg = rngCl.Interior.Color
Application.ScreenUpdating = False
With ActiveSheet.UsedRange
For xRows = .Rows.Count To 1 Step -1
For xCol = 1 To .Columns.Count
If .Cells(xRows, xCol).Interior.Color = colorLg Then
.Rows(xRows).Delete
Exit For
End If
Next xCol
Next xRows
End With
Application.ScreenUpdating = True
End Sub
From my research I've realised that I need to change this line
VBA Code:
For xRows = .Rows.Count To 1 Step -1
Also I basing to on this VBA I've tried to make another one which will scroll the view to the next color in the given column, but my attempts to do that came to nothing. If someone will have some free time and good will I will really appreciate the help.
Best regards,
Tom.