Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
I have this code that assess a range of cells and formats individual cells within that range based on values preceeding and proceeding that cell.
Someone here at Mr Excel was kind enough to provide this code for me, so I'm not extirely certain I know how it works, especially how the variable 'c' works.
When I reach the line I get a "Type mismatch" error when it encounters a cell that has the value "AUTO" in it.
This code is supposed to reformat all cells in that range when the criteria is met except if the cell has a value of "AUTO". Those cells will not be reformatted.
Is anyone able to share how to resolve the error and do what I set out to do with this code? For what I can gather, 'c' must be a range maybe ... something that can't be compared.
Rich (BB code):
With ws_cs.Range("H" & dr_trow & ":Q" & dr_trow) 'Rows(dr_trow)
On Error Resume Next
Set c = .SpecialCells(xlConstants) 'cells with content (not empty, not formulas)
If c Is Nothing Then MsgBox "no cells", vbCritical: Exit Sub
On Error GoTo 0
If c <> "AUTO" Then
For Each cl In c.Cells 'loop through this cells
If cl.Column = 1 Then bLeft = False Else bLeft = (cl.Offset(, -1).Interior.ColorIndex = xlNone And Len(cl.Offset(, -1).Value) = 0) 'the cell at the LHS is empty and no color
If cl.Column = ActiveSheet.Columns.Count Then bRight = False Else bRight = (cl.Offset(, 1).Interior.ColorIndex = xlNone And Len(cl.Offset(, 1).Value) = 0)
If Not bLeft And Not bRight Then cl.ClearContents
Next
End If
End With
Someone here at Mr Excel was kind enough to provide this code for me, so I'm not extirely certain I know how it works, especially how the variable 'c' works.
When I reach the line I get a "Type mismatch" error when it encounters a cell that has the value "AUTO" in it.
This code is supposed to reformat all cells in that range when the criteria is met except if the cell has a value of "AUTO". Those cells will not be reformatted.
Is anyone able to share how to resolve the error and do what I set out to do with this code? For what I can gather, 'c' must be a range maybe ... something that can't be compared.