Environ to use username as variables?

burns14hs

Board Regular
Joined
Aug 4, 2014
Messages
76
Hello All,

I have the following code that works really well. What I would like to do though, is have a list on a worksheet where people can add their usernames and become part of the AdminAccess group. In the italicized line, I would like to use variables to pull the cell value from that sheet/column (Sheets("Lists").Range("F1").Value (through F25 Value)). When I attempted to Dim some set of variables and put them in there I can't get it to work. Any ideas? I have already tried the variable individually both with and without the "" and I tried using an array() which also didn't work.


Code:
    Login = Environ("UserName") 'Environ("UserName") grabs the login name attached to your profile on your computer

[I]    AdminAccess = InStr("burnsjas-mslinde-jodruin", Login) > 0[/I]

    If AdminAccess Then
        Columns("K:K").Select
        ActiveWorkbook.Worksheets("Data").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add Key:=Range("K1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Data").Sort
            .SetRange Range("A2:M1000")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End If
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try using this:

Code:
AdminAccess = Not IsError(Application.Match(Login, Sheets("Lists").Range("F1:F25"), 0))
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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