I am trying to create a code that solves the following criteria: If a specific cell in column C equals zero, delete row If a specific cell in column U STARTS with 9, delete row If a specific cell in Column E is a negative value, delete row If a specific cell in column C starts with 2015, highlight color If a specific cell in column C starts with 2016, highlight same color as above If a specific cell in column C starts with 2017, highlight with different color All else, leave
This is what I have so far and I keep getting coding errors. I know this is very specific, any help is greatly appreciated
Sub Module()
Dim x As Long
Dim lastrow As Long
Set sSheetName = ActiveSheet.Name
With Worksheets(sSheetName)
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For x = lastrow To 1 Step -1
If Cells(x, 3).Value = 0 Then .EntireRow.Delete
If Left(Cells(x, 21), 1) = 9 Then .EntireRow.Delete
If Left(Cells(x, 5), 1) = "-" Then .EntireRow.Delete
If Left(Cells(x, 3), 4) = 6017 Then
cell.Offset(, -6).Resize(, 21).Interior.ColorIndex = 39
If Left(Cells(x, 3), 4) = 6018 Then
cell.Offset(, -6).Resize(, 21).Interior.ColorIndex = 39
If Left(Cells(x, 3), 4) = 6150 Then
cell.Offset(, -6).Resize(, 21).Interior.ColorIndex = 43
Else
cell.EntireRow.Interior.ColorIndex = xlNone
End If
End Sub
.Cells
instead ofCells
. Iscell
a variable or a typo? – gizlmosSheetName
? You haven't defined it. Probably a string - in that case remove theset
when assigning the name of the sheet. – FunThomasWith
.EntireRow.Delete
isn't valid. You need e.g..Cells(x,3).EntireRow.Delete
– Steve Lovell