Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:54:21+00:00 2026-05-21T06:54:21+00:00

I have a vba userForm that has 36 buttons on it. I would like

  • 0

I have a vba userForm that has 36 buttons on it. I would like to disable all buttons when a value on one of my spreadshets reaches a certain number. Right now with each click of a button a number goes up by one on the spreadsheet I’m referencing. When the number reaches three I would like to disable all buttons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:54:22+00:00Added an answer on May 21, 2026 at 6:54 am
    Dim oCtrl As Control
    Dim oButton As CommandButton
    
    For Each oCtrl In MyForm.Controls
        If oCtrl.Tag = "SomeValue" Then
            Set oButton = oCtrl
            oButton.Enabled = False
        End If
    Next
    
    Set oCtrl = Nothing
    Set oButton = Nothing
    

    If you have other buttons which you do not want disabled, the solution is to use the Tag property. Set the Tag property on all the buttons which you will want to enable or disable together to the same value. Then you can check for that value in a look and enable/disable them. Another way is to name them the same prefix or suffix and check for that in your code.

    Addition

    Btw, the Control object does not have an Enabled property. So you must “cast” it to a CommandButton to disable it. Apparently a Control object does have an Enabled property but it does not show in intellisense. However, you should still try to cast the Control to a CommandButton to ensure that’s what you have. Here’s an expanded version:

    Dim oCtrl As Control
    Dim oButton As CommandButton
    
    For Each oCtrl In MyForm.Controls
        If oCtrl.Tag = "SomeValue" Then
            On Error Resume Next
            Set oButton = oCtrl
            On Error GoTo 0
    
            If Not oButton Is Nothing Then
                oButton.Enabled = False
            End If
        End If
    Next
    
    Set oCtrl = Nothing
    Set oButton = Nothing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel2010 VBA userform that has one comboBox, from which the user
Does VBA have dictionary structure? Like key<>value array?
Using VBA i have a set of functions that return an ADODB.Recordset where all
i have a vba line of code like this: ActiveCell.FormulaR1C1 = =LOOKUP(ETG_C,RC[-10],RC[-8]) i would
In excel vba I have added a commandbutton to userform... like below Set ctrl
I currently have some VBA code that runs through and modifies all my calendar
I have a userForm that consists of some buttons that have images on them.
Using Excel 2002 and have a VBA app that has some UserForms. The main
I have some VBA code that looks like this and the aim is to
I have a VBA Word Macro that gets words from .txt list and color

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.