Hide Columns with Dropdown Lists - excel

I am creating a form which has a dropdown for the user to select which platform their conference will be on. So the dropdown has two values, "Type1" and "Type2". Depending on which they choose, I would like the user to see the options for that specific value, from which they can choose to add. These options cells have a "true/false" checkbox. So if Type 1 is selected, I only want to see the rows where "Type 1" options are. And if Type 2 is selected, I only want to see "Type 2" options. I was able to get this to work with a formula for the sheet:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim TrigerCell As Range
Set Triggercell = Range("C29")
If Not Application.Intersect(Triggercell, Target) Is Nothing Then
If Triggercell.Value = "Type1" Then
Rows("38:42").EntireRow.Hidden = True
Rows("32:37").EntireRow.Hidden = False
ElseIf Triggercell.Value = "Type2" Then
Rows("32:37").EntireRow.Hidden = True
Rows("38:42").EntireRow.Hidden = False
End If
End If
End Sub
The problem I have is even though those rows are hidden, all of the check boxes are stacking into one cell. So the cells are hiding, but the checkboxes in those cells are not. Is there some way to make the checkboxes "stick" in the cell so when the cell is hidden, so is the dropdown. I also noticed that if I copy a cell with a dropdown above it and paste it into a new cell, it copies and pastes the checkbox for that cell and the one above it. What am I missing?

Related

How to hide columns if a specific row does not match dropdown menu item?

I have a dropdown menu with entries connected to conditional formatting to change the color. This color coding is used in a specific row of each column in the range. When I change the dropdown selection, the cell changes color. I want to be able to make a new selection from the dropdown and have the columns where that specific row does not match the dropdown color be hidden.
Sub EffectFilter(ByVal Effects As Range)
' Dimensionalization
Dim KeyCells As Range
' Initialization
'Setting the range of the CEM Effects
Set KeyCells = Range("Q31:BS31")
'Body
' Detect Background Color of "Filter Effects" cell, Compare to Effects cells Background colors
If Not KeyCells.Interior.ColorIndex = Range("G1:H1").Interior.ColorIndex Then
KeyCells.EntireColumn.Hidden = True
End If
End Sub
This is my code currently. When I pull up the macros tab, it is not present, so I assume it will execute automatically when the color of Range("G1:H1") changes. Cells G1 and H1 have been merged and centered, but nothing currently happens to the columns when I change the dropdown menu selection. Each of the columns in the Range("Q31:BS31") can be or is a different color, but the colors do repeat. I made sure the colors for the dropdown are the exact same as those present in the columns. What I am hoping to do is to select something from the dropdown and the color of that cell will change (This part works already) and the Columns in which Row 31 is not that color will be hidden. I do plenty of things with VBA where you press a button to run a macro, but this is my first time trying to do something automatically like this, so I may be a bit slow to understand at first, but any help is greatly appreciated.
Use the Worksheet_Change event handler (and ensure the code is in the sheet code module, not a regular module).
Use a loop over the columns to be hidden.
You can think of the value of the dropdown (merged cell) as being stored in the top left corner. So use Range("G1"), not Range("G1:H1").
Color or ColorIndex applied by conditional formatting is accessed using .DisplayFormat.Interior.
Private Sub Worksheet_Change(ByVal Target As Range)
' Only proceed if the dropdown changed
If Intersect(Target, Me.Range("G1")) Is Nothing Then Exit Sub
Dim KeyCells As Range, cell As Range
Set KeyCells = Me.Range("Q31:BS31")
' Unhide all columns by default
KeyCells.EntireColumn.Hidden = False
For Each cell in KeyCells
If cell.DisplayFormat.Interior.ColorIndex <> Me.Range("G1").DisplayFormat.Interior.ColorIndex Then
cell.EntireColumn.Hidden = True
End If
Next
End Sub

Allow Specific Cells to be selected when another cell's value is equal to 1 or 2

This sounds easy but i cant get my code to work for some reason.
i have a dynamic chart which updates based on cell selected in Column A. i have a dropdown menu that contains 2 items: Element and Subcategory. when the Element item is selected, the cells A9 to 13 gets populated with Element items. when the dropdown is set to Subcategory, the cells A9 to a23 gets popultaed with Subcategory items.
To limit cells that can be selected, i want to lock the worksheet. i can do that by just setting a password for the worksheet however, i also want to be able to lock/unlock the cells with the Elements and Subcategories based on the selection from the dropdown.
that is, if the dropdown is set to Elements, the user should only be able to select cells from A9 to A13. if the dropdown is set to Subcategory, then the user should only be able to select from cells A9 to A23.
the screenshot below is my Dashbboard worksheet. the Dropdown menu is linked to A8 in my Formulas worksheet. i set the dashboard worksheet to locked with a password, im expecting the worksheet to allow me to select the cells in the code when i change the dropdown value but they stay locked.
here's the code i put in my Formulas worksheet
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsdashboard2 As Worksheet
Set wsdashboard2 = Sheets("Dashboard2")
If Range("A8") = "1" Then
wsdashboard2.Range("A8:A13").Locked = False
ElseIf Range("A8:A23") = "2" Then
wsdashboard2.Range("A8:A23").Locked = False
End If
End Sub

Block cells without block the list

Is there any way to block cell without block list?
Ex: I have in cell A1 the list:
Brazil
USA
Ireland
If I block the cell using "protect sheet"
I can't select the list
If I block on VBA using the code application.cutcopymode = false
It works, but if the person paste from a notepad, for example, it doesn't work
Is there any way to block it?
Private Sub Worksheet_SelectionChange(ByVal Target as Range)
If intersect(Target, range("A1")) is nothing then Exit Sub
Application.CutCopyPaste = False
End sub
I don't think you can do so (curious if I'm wrong).
What you could do however:
1) Developers > Insert > Combobox
2) Align Combobox with cell A1
3) Assign the appropriate list and a linked cell
4) On the Protection tab, select the Locked check box
5) On linked cell make sure you deselect the Locked check box
6) Protect your worksheet
Pasting values in cell A1 no longer possible, users deleting/moving/shaping your combobox is disabled AND you can still use the validation list :)

Excel macro for cell fill in with one click based on dropdown list

I want to fill a range of cells let's say A1:A5 with the value that is in a drop down list let's say in B1, by clicking once with the mouse in cells A1:A5. The way i want it to work is to first select the value that i want from the dropdown list and then click in in any of the cells from range A1:A5, and only the cell selected changes the value to the value from the dropdown list. And also when i change the value from the dropdown list the cells that were previously filled by clicking them do not change automatically to the new value from drop down. Once clicked they remain to that value until clicked to another selected value.
Add data validation to B1, under "Allow:" you pick "List", under "Source:" your values like: Value1,Value2,Value3... .. or of course a range..
Paste the following in sheet code(eg Sheet1(sheet1))
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
Selection.Value = Range("B1").Value
Range("B1").Value = ""
End If
End Sub

Linking Excel ComboBox with List Based on Independent Cell

I'm attempting to add items to an Excel Combobox, based on the value of an independent cell. So what I need is an IF statement, obviously.
So it should look something like this, (note: C1 is the independent cell):
IF C1 = "3"
AddItem "One"
AddItem "Two"
ELSE IF C1 = "4"
AddItem "Three"
.etc.
The problem is that I don't know how to properly link the ComboBox such that it knows when the independent cell value has changed to trigger a clearing of existing items in the ComboBox and repopulation of new items.
This code needs to go on the sheet with your target cell C1
Every time your cell C1 is changed, it will force the code you insert to execute. In this case, it will force an update to your dropdown list.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("C1"), Range(Target.Address)) Is Nothing Then
Application.EnableEvents = False
'YOUR CODE HERE
Application.EnableEvents = True
End If
End Sub
Edit 1: (How to add items to a combo box?)
Add an ActiveX Control Combo Box
Developer Tab > Insert > ActiveX Controls > ComboBox
You can then refer to your Combo box inside your loop as follows:
Combobox1.Clear 'To clear
ComboBox1.AddItem "Text" 'To Add

Resources