Type Mistmatch Error

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I am trying to write a macro that will search the first
row of each column and then change the background color of
the column based on its value. Whenever I run the code, I
get a Type 13 Mismatch Error and I am not sure how to fix
it. Any advice?
Here is the source of the problem:

For ColumnIndex = 1 To 1000
With ActiveSheet.Cells(ColumnIndex)
If ((.Value) = "Q") Or ((.Value) = "T") Then
Columns(ColumnIndex).Interior.ColorIndex = 15

Thanks,
Matt
 
-----Original Message-----



Matt,
It worked for me. You need to be sure columnindex is dimensioned as
integer.

Bob L.


.
Bob -
I was just leaving out that one part - thanks for your
help,
Matt
 
Do you have any errors in your data div/0!, #ref!, #n/a's?

Option Explicit
Sub testme00()
Dim columnIndex As Long

For columnIndex = 1 To 255
With ActiveSheet.Cells(1, columnIndex)
If IsError(.Value) Then
'do nothing
ElseIf ((.Value) = "Q") Or ((.Value) = "T") Then
Columns(columnIndex).Interior.ColorIndex = 15
End If
End With
Next columnIndex

End Sub

I changed your loop to 1 to 255.
I changed the .cells(columnindex) to .cells(1,columnindex)
 
Back
Top