Replacing values of a variable in VBA

FoeHunter

Board Regular
Joined
Nov 12, 2008
Messages
236
I have a form that allows the user to have the system automatically enter their name into the form using the code below. 9 out of 10 times this works great, except for someone who has a common name, then they have a number added at the end.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Here is the code that I have to start with that removes the period between the first and last name.
<o:p> </o:p>
Code:
    UserName = Environ("USERNAME")
    Me.Text1 = UserName
    Me.Text1 = Replace(UserName, ".", " ")
<o:p> </o:p>
For the sake of being ridiculous and covering every possible combination, let’s say I have an employee with the name Bob.Jenkins1234567890. How can I have VBA replace multiple values in one pass, or how do I set it up to run multiple lines of code? I figured it would be as easy as copy/paste the replace line and replace the dot with a number, but only the last line of code is updated on the screen.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Not sure if You'll ever got John.Smith10 or John.Smith100 but this would cover all the bases:
Code:
    UserName = Environ("USERNAME")
    Do While (IsNumeric(Right(UserName,1))) AND (Len(UserName) > 0)
        UserName = Left(UserName, Len(UserName) - 1)
    Loop
    Me.Text1 = Replace(UserName, ".", " ")
 
Upvote 0

Forum statistics

Threads
1,224,614
Messages
6,179,906
Members
452,949
Latest member
beartooth91

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