0
Dim mm As String
Dim lstRow As Integer
Set ws1 = ast.Sheets("Exit")
lstRow = ws1.Range("S" & ws1.Rows.Count).End(xlUp).Row
Dim i As Integer
For i = 2 To lstRow
    **If Len(ws1.Range("S" & i).Value) = 6 Then**
        mm = Left(ws1.Range("s" & i).Value, 3)
        ws1.Range("T" & i).Value = mm
        ws1.Range("T" & i).Interior.Color = vbRed
    End If
Next

I am going to take 3 alphabet of S column value and bring out these alphabet into T column with red color. But I am facing type mismatch error in ** line. ast is file name and ws1 is worksheet name.

Smandoli
  • 6,919
  • 3
  • 49
  • 83
Nitin
  • 5
  • 3
  • What appears on the Immediate Window if you put `Debug.Print Len(ws1.Range("S" & i).Value)` just before the problem line? – Smandoli Mar 08 '16 at 12:24
  • that doesn't make sense to me at all... still try to change all your "integer" to "long" [Why Use Integer Instead of Long](http://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long/26409520#2640952)... there may be a silent overflow... also try a `Debug.Print ws1.Range("S" & i).Value` in front of your error-line... if there is no error, then `Len` can't error (in theory) – Dirk Reichel Mar 08 '16 at 12:57
  • @Smandoli just a hint: in the direct window, you can use `?` in place of `Debug.Print` :) – Dirk Reichel Mar 08 '16 at 12:58
  • I have changed data types integer to Long but till now its showing same error. – Nitin Mar 08 '16 at 13:21

1 Answers1

0

Well I guess this might have somethign to do with it?

 Dim lstRow As Integer

VS

 lstRow = ws1.Range("S" & ws1.Rows.Count).End(xlUp).Row

is it a range or an integer? the line debugs on you b/c its told to look at it one way but youre using it in another way

Doug Coats
  • 6,255
  • 9
  • 27
  • 49