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
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,066
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Try using this:

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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,066
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Glad to help. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,461
Messages
5,596,274
Members
414,050
Latest member
Rick Royer

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
Top