[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB Command button

Posted on 2012-08-21
5
Medium Priority
?
803 Views
Last Modified: 2012-08-21
Private Sub CommandButton5_Click()
ActiveCell.Value = VBA.Environ("USERNAME")
ActiveCell.Offset(0, 1).Select
End Sub

Please can you help, I want to change the command button code so that if the value equals the following it will change to:-

"0123" change to "Tom"
"0124" change to "Sarah"
"0125" change to "Nick"
"0126" change to "Sophie"
0
Comment
Question by:Kiwi-123
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Norie
ID: 38318629
If what value, the username?
0
 

Author Comment

by:Kiwi-123
ID: 38318649
Hi Imnorie

the environ would equal the 0123 etc, but I'd want the code to use the nickname "Tom"
0
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 38318666
If there are only 4 names.
Private Sub CommandButton5_Click()
Dim strName As String
    Select Case VBA.Environ("USERNAME")
        Case "0123"
            strName = "Tom"
        Case "0124"
            strName = "Sarah"
        Case "0125"
            strName = "Nick"
        Case "0126"
            strName = "Sophie"
    End Select

    ActiveCell.Value = strName
    ActiveCell.Offset(0, 1).Select
End Sub

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 38318715
Something like this might work?

Select Case VBA.Environ("USERNAME")
  Case "0123"
    ActiveCell.Offset(0, 1).Value = "Tom"
  Case "0124"
    ActiveCell.Offset(0, 1).Value = "Sarah"
  Case "0125"
    ActiveCell.Offset(0, 1).Value = "Nick"
  Case "0126"
    ActiveCell.Offset(0, 1).Value = "Sophie"
End Select

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 38318716
Ooops.  Too late....didn't refresh...ignore me...
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question