Jun 14 2022 01:49 PM
I just upgraded to Office 365 and now one of my macros is generating a Type Mismatch error. The macro is pasted below, and the offending code is highlighted in red, bold italics. I would greatly appreciate any help. Thanks in advance.
Sub ColorRows2()
'
' ColorRows Macro
' Macro recorded 1/17/2020 by Steven Lapidus
'
Dim RowDef As String
Dim Processed As String
Dim Paid As String
Dim I As Integer
Dim ClaimsNo As Integer
Range("O1").Select 'Select Cell for Count Formula
ActiveCell.FormulaR1C1 = "=COUNTA(R[1]C[-14]:R[299]C[-14])" 'Count Data Rows
ClaimsNo = ActiveCell.Value 'Save Number of Claims
Range("A2:M300").Select 'Select All Data Rows in Array
Selection.Interior.ColorIndex = xlNone 'Color all rows white (no fill)
'Response = MsgBox(Counter)
I = 1
Application.ScreenUpdating = False 'Turn off screen refresh
Do While I <= ClaimsNo
I = I + 1 'Increment row counter
RowDef = "A" & I & ":M" & I 'Define current row
Processed = Range("F" & I) <> Blank 'If Adjusted then Processed
NotProcessed = Range("F" & I) = Blank 'If not Adjusted then Not Processed
Paid = Range("J" & I) <> Blank 'If Date Paid then Paid
NotPaid = Range("J" & I) = Blank 'If not Date Paid then Not Paid
'Response = MsgBox(I & Processed)
'Response = MsgBox(I & Paid)
If NotProcessed Then 'If not processed by insurance company
Range(RowDef).Select 'Select row
Selection.Interior.ColorIndex = xlNone 'Color row white (no fill)
ElseIf Processed And NotPaid Then 'If processed but not paid
Range(RowDef).Select 'Select row
With Selection.Interior
.ColorIndex = 36 'Color row yellow
.Pattern = xlSolid
End With
Else 'If processed and paid
Range(RowDef).Select 'Select row
With Selection.Interior
.ColorIndex = 35 'Color row grey
.Pattern = xlSolid
End With
End If
Loop
Call SortExpenses
Application.ScreenUpdating = True
End Sub
Jun 14 2022 02:10 PM
Jun 15 2022 04:18 PM
Thank you for your excellent suggestions! I hadn't thought about Conditional Formatting, but that's a great recommendation.
Declaring variables in one location is also a good habit, in fact, back in the day when I was a programmer, that was always my style and recommendation. However, I'm not a VBA programmer and typically fly by the seat of my pants! With that said, I changed all my variables to "variant" and that seems to work.
Thanks again for your comments and suggestions!!!
Jun 15 2022 06:52 PM
Jun 16 2022 06:01 AM