ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type Mistmatch Error (https://www.excelbanter.com/excel-programming/275021-re-type-mistmatch-error.html)

Dave Peterson[_3_]

Type Mistmatch Error
 
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)



Matt wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 01:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com