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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coverting a string to an integer

Status
Not open for further replies.

AliJay

Technical User
Sep 19, 2004
27
SG
Hi all,

First post so please bear with me.

I’m using Excel and writing a macro. A value is generated as a a string which has a value “id12456” and I want to convert it to an integer which is equal to 12456. How do I get rid of the “id” bit in front of the numbers?

I know it’ll be simple but thanks a million in advance for your help

AliJ
 
Thanks Will - I'll check it out.

All the best
 
Sub test()
in_string = "id1234567"
my_val = Val(Right(in_string, Len(in_string) - 2))
End Sub
 
Will the string always be in the format id12345, or are there varying alphabetic characters that may be placed in front? ETID's solution will work if the string is of static length and format.

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
Hi Guys,

The layout of the string will always have "id" in front of it but the length of the "numbers" part will vary.

Really appreciate your help on this.

AJ
 
In which case ETID's function will work

Rgds, Geoff

Yesterday it worked. Today it is not working. Windows is like that.

Please read FAQ222-2244 before you ask a question
 
This sub accounts for varying length, and is dependant on a 2 position alpha lead in.

my_val = Val(Right(in_string, Len(in_string) - 2))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top