CommandButton(1).visible code needed to fix

ColinCoady

New Member
Joined
Mar 21, 2019
Messages
35
Hi All
I want to add another section of code that will make my commandButton1 visible or not based on all 5 cells having data. If all five have data then show button if not don't show button. The 5 cells are, A3, A4, A5, A6, A7.
I've got the code to do this for commandButton2 based on one cell having data or not - works great.
I want get CommandButton1 to work based on more than 1 cell having data. Need 5 cells to all have data before showing the button.

Also to test if I just copy the code starting at Application.ScreenUpdating... and change the CommandButton2 to CommandButton1 and change the Cells(4,2) to (3, 2) it does not work. CommandButton2 will still work though (visible or not).
What am I doing wrong?

I removed the test code for commandbutton1. Can you share how to get the commandButton1 to be visible or not?
The first 7 lines of code do something else for me and are working as they should.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B5")) Is Nothing Then
If Range("B5") <> "" Then Range("B6:B11").ClearContents
End If
If Not Intersect(Target, Range("B6")) Is Nothing Then
If Range("B6") <> "" Then Range("B7:B11").ClearContents
End If




Application.ScreenUpdating = False
    If Cells(4, 2).Value <> "" Then
        Me.CommandButton2.Visible = False
    Else
        Me.CommandButton2.Visible = True
    End If
            
Application.ScreenUpdating = True


End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Thank you mikerickson

Last closing bracket missing and I made mistake on the cells - should have been B3:B6 and B13.
I got a run time error '13' type mismatch.

Also where should I place this code?
I'm very new at code.

Thanks
-Colin
 
Upvote 0
This did the trick but there probably is a shorter way around this.

Thanks everyone
Code:
Application.ScreenUpdating = False
    If Cells(4, 2).Value <> "" Then
        Me.CommandButton2.Visible = False
    Else
        Me.CommandButton2.Visible = True
    End If
    If Cells(3, 2).Value <> "" And Cells(4, 2).Value <> "" And Cells(5, 2).Value <> "" And Cells(6, 2).Value <> "" And Cells(7, 2).Value <> "" And Cells(13, 2).Value <> "" Then
        Me.CommandButton1.Visible = True
    Else
        Me.CommandButton1.Visible = False
    End If
Application.ScreenUpdating = True
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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