I have inserted a combo box with 3 named ranges showing detailed data and 3 options in the dropdown ('A', 'B', 'C'). I would like to write a macro to assign to the combo box so that if the user selects 'A' from the dropdown, my named range called 'NR1' is visible whilst my other two named ranges 'NR2' and 'NR3' are hidden. Then if 'B' is selected, 'NR1' and 'NR3' named ranges are hidden. Then if 'C' is selected, 'NR1' and 'NR2' named ranges are hidden. The VBA is as follows but I get an error message saying 'Object required'.
Any assistance would be greatly appreciated.
Sub ComboBox1_Change()
If ComboBox1.Value = "A" Then
Range("NR1").EntireRow.Hidden = False
Range("NR2").EntireRow.Hidden = True
Range("NR3").EntireRow.Hidden = True
ElseIf ComboBox1.Value = "B" Then
Range("NR2").EntireRow.Hidden = False
Range("NR1").EntireRow.Hidden = True
Range("NR3").EntireRow.Hidden = True
ElseIf ComboBox1.Value = "C" Then
Range("NR3").EntireRow.Hidden = False
Range("NR1").EntireRow.Hidden = True
Range("NR2").EntireRow.Hidden = True
End If
End Sub
As mentioned by Soctt Craner, NR1...NR3 are cell names within the worksheet. Rename the ranges such as Nrng1, Nrng2, Nrng3. I've tested your code with a combobox inserted on the sheet and it is all fine.