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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,215,679
Messages
6,126,183
Members
449,296
Latest member
tinneytwin

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