Type data mismatch in VBA

dbrice

New Member
Joined
Feb 15, 2017
Messages
9
How do I get around this problem?
Some of the cells are text, some formulas, and some numbers (but the numbers are formatted as text).

Sub Apply_Color_To_Text2()


' Declarations and Initialisation
Dim Row As Integer, Col As Integer
Dim CurrentCellText As String
Col = 1


' Loop Through Rows 2 to 5
For Col = 2 To 150
For Row = 24 To 55


' Get Text in Current Cell
CurrentCellText = ActiveSheet.Cells(Row, Col).Value '***The Debugger stops here ***


' Get the Position of the Text SPO
SPOStartPosition = InStr(1, CurrentCellText, "SPO ")

' Colour the Word SPO Red
If SPOStartPosition > 0 Then
ActiveSheet.Cells(Row, Col).Characters(SPOStartPosition, 4).Font.Color = RGB(0, 112, 192)
End If


Next Row
Next Col
' Change color in specific cell
'ActiveSheet.Cells(8, 58).Characters(0, 2).Font.Color = RGB(255, 0, 0)


End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What is the value of Row and Col at the point it stops and what is in that cell?
 
Upvote 0
Thanks, your hint helped me figure it out. I didnt know that if you hover the mouse over the "Row" or "Col" it would tell you the value of those at the point of the error.

As it turns out the value was #N/A. it came from the formula:
=MATCH("Morn",'Officer List'!$B:$B,0)+MATCH("AD",INDIRECT("'Officer List'!E" & MATCH("Morn",'Officer List'!$B:$B,0) & ":E300"),0)-1, "")=IFERROR(MATCH("Morn",'Officer List'!$B:$B,0)+MATCH("AD",INDIRECT("'Officer List'!E" & MATCH("Morn",'Officer List'!$B:$B,0) & ":E300"),0)-1

I fixed it by handling the error:
=IFERROR(MATCH("Morn",'Officer List'!$B:$B,0)+MATCH("AD",INDIRECT("'Officer List'!E" & MATCH("Morn",'Officer List'!$B:$B,0) & ":E300"),0)-1, "")
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,037
Members
449,062
Latest member
mike575

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top