Command button

Ron99

Active Member
Joined
Feb 10, 2010
Messages
347
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have created command buttons in my worksheet, I want to add codes which is in modules to that button, unfortunately it is not adding. Is there a way to do this ? other than copying the code from mdoules and pasting it in the command button.

Thanks
Ron...
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
... have you checked for a trailing space character in the sheet tab name?
 
Upvote 0
The best thing I did was, I copied the name from the tab itself, now it works..may be there was an extra space I had added.

Thanks Guys!!
 
Upvote 0
I have one more query...

I do not want everyone to use the button, I want only specific people to use it, is there a way we can protect the buttons from misuse ?

Regards,
Ron.......
 
Upvote 0
You can check against the Windows logon name like this

Rich (BB code):
Sub Macro1()
'
' Macro1 Macro
'
'
Dim LR As Long, _
LC As Long, _
dWs As Worksheet, _
sWs As Worksheet, _
rowx As Long, _
Rng As Range, _
rng1 As String
If Environ("username") <> "Ron" And Environ("username") <> "VoG" Then Exit Sub
Sheets("GSC ACTIVITIES").Select
Set sWs = ActiveSheet
 
Upvote 0
See if this returns your username correctly. If it does, you could just wrap the code with an IF and test for acceptable usernames.
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> tryme()<br>    MsgBox Environ("username")<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
How do I add this code in a particular button ?

I have three buttons in sheet called " Button sheet"

I have a button named " sort data", "Extract data", "send mails"

all of the above in this button I have assigned to modules, should I add your given code in the modules or in the sheet called "button sheet" by pressing alt+f11 ?

where and how do I add it ? please advise

Thanks
 
Upvote 0
I have pasted the code

Sub Macro1()
'
' Macro1 Macro
'
'
Dim LR As Long, _
LC As Long, _
dWs As Worksheet, _
sWs As Worksheet, _
rowx As Long, _
Rng As Range, _
rng1 As String
If Environ("username") <> "Ron" And Environ("username") <> "Kjell" Then Exit Sub
Sheets("GCS Activities").Select


when I click on the button, nothing is happening.

in (username), should I have to specify something..

Sorry I am new to VBA..
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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