Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > PC based Database Applications > Microsoft Excel > Back to basics anyone?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-06-08, 13:41
JAustin JAustin is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
Back to basics anyone?

I'm working on programming my first VB userform / function. I openly admit, I barely know what I'm doing. But I'm working on a project and thought perhaps I could resolve an issue by writing an excel function in visual basic.

Can anyone explain how to write the code for a program that would help me seperate a column of alpha numeric data? (i.e. 123AP value is in column A. The program would generate value "123" into Column B and "AP" into Column C.

Any information is Greatly Appreciated!

Thanks,

Jesse
Reply With Quote
  #2 (permalink)  
Old 08-20-08, 16:51
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Posts: 82
If you're certain that the string will always be numeric on one side and text on the other, it's fairly simple to write a custom function to do this.

Code:
Function SplitString(strStart As String, booSide As Boolean) As Variant 'Function to split a string composed of numeric and non-numeric characters 'booSide determines if the return value will be the numeric side (left, true) or the 'non-numeric side (right, false). Dim strWorking as String 'Working variable Dim strTemp as String 'Holder for return value strWorking = strStart If booSide Then 'Parse strWorking from the left until you run out of numeric characters Do While IsNumeric(Left(strWorking, 1)) 'Add the character to the return variable strTemp = strTemp & Left(strWorking, 1) 'Lop off that character from strWorking strWorking = Right(strWorking, Len(strWorking)-1) Loop Else 'Parse strWorking from the right until you reach numeric characters Do Until IsNumeric(Right(strWorking, 1)) 'Add the character to the return variable strTemp = Right(strWorking, 1) & strTemp 'Lop that character from strWorking strWorking = Left(strWorking, Len(strWorking)-1) Loop End If 'Populate the function with the return value SplitString = IIf(booSide, CLng(strTemp), strTemp) End Function

NB
I haven't tested this, but it looks about right. To use it, enter your value in A1, "=SplitString(A1, True)" into B1 and "=SplitString(A1, False)" into C1.

Good luck!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On