Hide combobox cased on cell value

roxaas

New Member
Joined
Nov 4, 2011
Messages
9
I'm trying to hide a combobox if cell V14 is 0 and display it if it's any other number. Below is the code that I have.

Been stuck on this for too long. Time to get some help :)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("v14")) Is Nothing Then
    If Range("v14").Value > 0 Then
        Me.ComboBox1.Visible = True
    Else
        Me.ComboBox1.Visible = False
    End If
End If

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Your code is working. Be sure that macro is available, disable Design Mode and check that the code is in the sheet’s VBA module where the ComboBox1 is.
To find the reason of the problem it is useful to place Option Explicit onto the top of VBA code and click VBE menu: Debug – Compile VBA Project.

A bit shortened code:
Rich (BB code):

' Code of the Sheet1 VBA module
' How to implement this:
' 1. Copy code to the clipboard (Ctrl-C)
' 2. Do right click on sheet's tab name
' 3. Choose Source code
' 4. Paste the code (Ctrl-V)
' 5. Press Alt-Q to close VBE
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("v14")) Is Nothing Then
    Me.ComboBox1.Visible = Range("v14").Value > 0
  End If
End Sub
 
Last edited:
Upvote 0
I figured out why it's not working. Cell v14 is a sum function that adds v2:v13. If it's a number, it works fine. Is there a way around this?
 
Upvote 0
Formula triggers Calculate event instead of Change one.
Use:
Rich (BB code):

Option Explicit
Private Sub Worksheet_Calculate()
  If Not Intersect(Target, Range("v14")) Is Nothing Then
    Me.ComboBox1.Visible = Range("v14").Value
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,073
Messages
6,182,707
Members
453,132
Latest member
nsnodgrass73

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