Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

type mismatch error

Status
Not open for further replies.

MuskyMan

Technical User
Jul 31, 2002
36
US
Hi. Running into a Type Mismatch error when running the loop below.

I receive a rather large spreadsheet (up 9000 rows on certain months) monthly and I need to highlight certain amounts. Problem lies in that some of the cells have text in lieu of numbers. I just want the Sub to ignore the cells with text.

Thanks in advance for any input that you may have.


Sub Highlite()
Dim i As Long

For i = Cells(Rows.Count, "B").End(xlUp).Row To 1 Step -1
If Cells(i, "C").Value > 1000 Then Cells(i, "C").Interior.ColorIndex = 6

End Sub

Next i
 
in your post next I is outside the sub. I am sure htis is a typo

Thanks Rob.[yoda]
 
have checked the coding and it highlights any value over 1000 for me if column b has data

Sub Highlite()
Dim i As Long

For i = Cells(Rows.Count, "B").End(xlUp).Row To 1 Step -1
If Cells(i, "C").Value > 1000 Then Cells(i, "C").Interior.ColorIndex = 6
Next i
End Sub



Thanks Rob.[yoda]
 
Rob, the loop works great until it reaches a cell where my salesperson types in "Nothing this month". This were I get the error. I can always use On Err Resume Next, however, I would like to eventually delete the text in the cell.. I don't know how to deal with both Text and Numbers in the same loop..

Thanks
 
You can play with IsNumeric

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
i had "Nothing in this month" in the column and it didnt error out, but PHV has suggested to do a check on isnumeric and then if not skip cell.

rob.

Thanks Rob.[yoda]
 
Thanks Rob and PHV, IsNumeric was the last step that I was looking for...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top