VBA Alternative to If Then Else

michaeltsmith93

Board Regular
Joined
Sep 29, 2016
Messages
83
The format of Application.UserName for people at my company is "Last, First". As a result, I've written a few lines that translate this to "First Last" and called it "FirstLast". I've used FirstLast throughout my code, but I'm now using the sheet with folks at another company whose UserName is already in format "First Last". Is there any way to get around writing an If Then Else statement (i.e., If InStr(1, Application.UserName, ",")) and putting my current code with "FirstLast" as the Then and copying and pasting my code and replacing "FirstLast" with Application.UserName in the Else? I see the same potential problem with Select Case.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
What's wrong with using an If statement?
 
Upvote 0
I wanted to avoid having to replace every instance of FirstLast with Application.UserName. I can use Find and Replace, but I just feel like an If statement is inelegant and wondered if I could somehow have Excel identify the format to begin with and use one variable in place of FirstLast and Application.Username, having already selected between the two at the beginning of the code. I guess that would involve For Each or something and might be less elegant/more processor-intensive?
 
Upvote 0
Without seeing your code you do something simple like
Code:
If InStr(1, Application.UserName, ",") Then
   'use you code
Else
   firstlast = Application.UserName
End If
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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