Disable Command Buttons

CampbellC

New Member
Joined
Dec 10, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
hi
I know how to disable command button with
cmd button .enabled = false
my Question is can I disable a selected group of buttons called cancelled with one bit of code instead of have to write them individual or from the property section select Order buttons are disabled though Property section on start up just looking for a easer way to do it
Screenshot 2021-12-14 120642.png
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
If the buttons have sequential numbers like CommandButton1, CommandButton2,...,CommandButton5, then :

VBA Code:
Sub try1()

For i = 1 To 5
Me.Controls("CommandButton" & i).Enabled = False
Next

End Sub
 
Upvote 0
Another option, populate the buttons name (e.g. "a", "b", "c") into an array:

VBA Code:
Dim x
For Each x In Array("a", "b", "c")
    Me.Controls(x).Enabled = False
Next
 
Upvote 0
my command button are name CmdSelectAord to CmdSelecford

Code:

Give me error could not find specific object
my attempt at it
Code:
guess ive written it wrong
 
Upvote 0
VBA Code:
For i = 1 To 5
Me.Controls("CmdSelectAord" & i).Enabled = True
Next
 
Upvote 0
my command button are name CmdSelectAord to CmdSelecford

Hi,
if you have named your commandbuttons CmdSelectAord to CmdSelectFord then try following & see if does what you want

VBA Code:
 Dim i As Long
    For i = 1 To 6
        Me.Controls("CmdSelect" & Chr(64 + i) & "ord").Enabled = True
    Next

Dave
 
Upvote 0
Solution
Got it working
just to be a pest what is chr 64
i just like to know how it works not just copy it
don't learn by just copying it

thanks Akuini
 
Last edited:
Upvote 0
Glad we were able to help & suggestion resolves

Char(64) is @ symbol in character set but you are using 64 + value of i in the For Next Loop - (65 to 70) which is A to F

You can find Character set information here: Character set (0 - 127)

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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