Find Cell strating with [1-9] but string value

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

I like to create a function that returns from a string true or false when the string starts with string between 1-9

Can someon help please?

VBA Code:
Function StartsWithNumer(strText As String) As Boolean
    If Left(strText, 1) = ["1-9"] Then
    StartsWithNumer = True
    
    End If
    
End Function

this is not working but not sure how to change it..

Many thanks

Albert
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this
Code:
Function StartsWithNumer(strText As String) As Boolean
  StartsWithNumer = Left(strText, 1) Like "[1-9]"
End Function
 
Upvote 0
try

VBA Code:
Function StartsWithNumber(ByVal strText As String) As Boolean
    StartsWithNumber = CBool(strText Like "[1-9]*")
End Function

Note:
not sure if your function name had a typo

StartsWithNumber

but I have included the b

Dave
 
Upvote 0
In addition to the Udf, and you already got working samples, you can do that via formula; for example:
Excel Formula:
=IF(AND(CODE(A2)<58,CODE(A2)>48),TRUE,FALSE)

Bye
 
Upvote 0
try

VBA Code:
Function StartsWithNumber(ByVal strText As String) As Boolean
    StartsWithNumber = CBool(strText Like "[1-9]*")
End Function

Note:
not sure if your function name had a typo

StartsWithNumber

but I have included the b

Dave
 
Upvote 0
Hi guys,

many thanks to you all! And yes I had a typo in my function...

I also tried in the meantime and came just up with a working function myself too ,)

VBA Code:
Function StartsWithNumber(strText As String) As Boolean
    If IsNumeric(Left(strText, 1)) Then
        StartsWithNumber = True
    End If
End Function
 
Upvote 0
Did not think isNumeric would work as it is a string..

Well learned something again.

Many thanks to you all for your input and help!

Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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