ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Newbie VBA: How to test second position in a cell? (https://www.excelbanter.com/excel-programming/300322-re-newbie-vba-how-test-second-position-cell.html)

ZoomZoom[_5_]

Newbie VBA: How to test second position in a cell?
 
I'd examine the value using Mid, then check to see if the Ascii code for
the extracted string lay in the correct range:

Dim str As String
str = Sheet1.Cells(1, 1).Value
If (str < "") Then
If (Asc(Mid(str, 2, 1)) 47 And Asc(Mid(str, 2, 1)) < 58)
Then
Sheet1.Cells(1, 2).Value = True
Else
Sheet1.Cells(1, 2).Value = False
End If
End If

There are probably vastly better ways of doing this though...


---
Message posted from http://www.ExcelForum.com/


ZoomZoom[_6_]

Newbie VBA: How to test second position in a cell?
 
You may have noticed I got it the wrong way round.
Anyway, here it is again but correct, a bit neater & with more
validation:

Dim str As String
str = Sheet1.Cells(1, 1).Value
If (str < "") And (Len(str) 1) Then
Sheet1.Cells(1, 2).Value = Not (Asc(Mid(str, 2, 1)) 47 And
Asc(Mid(str, 2, 1)) < 58)
End If



---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 07:04 AM.

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