Vba if statement help

bloodmilksky

Board Regular
Joined
Feb 3, 2016
Messages
202
Hi Guys,

I have a macro that enters the application username as per below. but one of the users names comes up with a dash and I am trying to say that if the username comes up with the dash then replace it with the name in the statement. but it keeps coming up with an error.

can anyone help please?

Code:
    Sheets("Request Form").Select    Range("B7").Select
    Selection.ClearContents
    Sheets("Request Form").Select
    Range("B7").Select
    Range("B7") = Application.UserName
    If Sheets("Request Form").Range("B7").Value ("James Charles-Bradfield") Then.("RJames Charles Bradfield")
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
May be better to use a Select in case you come across any other names that need changing in future:

Code:
    Sheets("Request Form").Select
    Select Case Application.UserName
        Case "James Charles-Bradfield"
            Range("B7").Value = "RJames Charles Bradfield"
        Case Else
            Range("B7").Value = Application.UserName
    End Select

WBD
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,217
Members
448,876
Latest member
Solitario

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