I am aware of how to create a combobox to emulate a data validation cell based off of a range list, featuring the ability to filter the dropdown list based on what you type in. This is similar in functionality to how column filtering in an Excel table works, where if I start typing "tor" it will immediately filter the preview window for items only containing the string "tor".
However, I am trying to create a report where every row requires the same dropdown menu, and ideally what I hope to do is have each row have this cell where you can click on the dropdown, start typing, and the list will narrow down. However, I realize a combobox is a unique object and it cannot be duplicated as simply as copying and inserting a row with a data validation field.
Is there a way I can easily duplicate this sort of drop down where a list preview filters based on what is typed into the cell, either via vba or plain data validation? In short, can a dropdown with the filtering preview capability as my code below be copied and pasted as easily as a simple data validated cell within a row?
For reference here is my combobox code, listing range A2:A791 on sheet DVTest:
Sub ComboBox1_Populate(Optional fltr As String)
ComboBox1.List =
Filter(Application.Transpose(Worksheets("DVTest").Range("A2:A791" &
SymbolCount).Value), fltr)
End Sub
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Call ComboBox1_Populate(ComboBox1.Text)
End Sub
Private Sub UserForm_Initialize()
Call ComboBox1_Populate
End Sub
Thanks kindly!
Related
Users will enter new information into a sheet using an userform. This information is tied to a unique ID given at time of entry (i.e. 2019-7 for the 7th item in this year). Currently, each piece of information is placed into separate cells in a row. I want to hide some of these cells but be able to allow users to click on the unique ID at the start of that row, which will run a macro that will create a new sheet to display all information in a user friendly way.
I have tried creating a hyperlink to a run a macro but the code for identifying the hyperlink can't be cell specific. I need a more dynamic way to have excel recognize which ID was clicked and then use that to gather the rest of the information in that row (i.e. the hidden columns).
My best option had been to put a private sub in the worksheet to recognize when a cell was changed/clicked but couldn't get past it just identifying the cell. I need it to then identify the contents of that cell, which would be the unique ID.
I have no issues with creating a hyperlink to nothing, I just need excel to run a macro when a hyperlink is clicked and then within that macro, identify the unique ID and/or row that was clicked. Once I have the ID or Row identified, I then can go from there to grab the rest of the info in the other columns.
You can use the BeforeDoubleClick event of the Worksheet:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address <> "$A$7" Then Exit Sub
' below, call the functions/subs that produce your output worksheet
MsgBox "You clicked on " & Target.Address
End Sub
Above only works on cell A7. If you need this to apply to entire column A, modify slightly:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
' below, call the functions/subs that produce your output worksheet
MsgBox "You clicked on " & Target.Address
End Sub
I'm creating a table in excel where the user can use a command button to create a clickable link to a document.
The table has various formulas to calculate dates etc. and it is an excel table, not a range of cells in excel.
So far I have copied the button for about 100 rows.
How do I get the file link button to repeat for each row?
Without the need of a CommandButton, the Code below combines Worksheet_SelectionChange and Intersect to create the link in the selected cell inside a specified Range as you click on it.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(ActiveSheet.Range("X3:X400"), Target) Is Nothing Then
ActiveSheet.Hyperlinks.Add Anchor:=Target, _
Address:="hhtp:\\YourLinkAddress.org", _
TextToDisplay:="Link"
End If
End Sub
Modify it to your Needs. You will get the values of the Row by using Target.Offset
In userform I inserted ComboBox and i have to add list through Array following are the code. I want that whether it is possible that in ComboBox list will get from a Range in sheet (like in case of Data Validation)
Private Sub UserForm_Initialize()
ComboBox1.List = Array("Item1", "Item2", "Item3", "Item4")
End Sub
you can use the range in the sheet to create, even a named range, e.g.:
combobox1.list = range(cells(1,1),cells(100,1)).value
combobox2.list = sheets(1).range("NamedRange")
arr = array("1","2","3")
combobox3.list = arr
This is how you'd use a range to set the row source of a combo box. You can also do this in vba.
Me.combobox1.RowSource = "MyRange"
You can set this to a Table (ListObject) instead of a static range. Create a Table with your list of values, instead of just using a static range of cells. This way when you need to add to the list, you simply enter the new values, which are added to the Table. In my example, I have a Table named "Table1" and a column with the heading "Numbers". Then call this function:
Private Sub UserForm_Initialize()
ComboBox1.RowSource = "=Table1[Numbers]"
End Sub
You have to do this on the Iniitalize, since setting the RowSource from the ComboBox Properties will cause Excel to crash the first time you add an item to your list.
This gives you a list that you can edit without having to edit the code behind the UserForm.
In my workbook, cells AR8:AS8 are merged and in the cell is a data validation dropdown list. The source of the list uses the formula =indirect(GG8) and this refers to lists in a different tab.
My problem is that when I click on the dropdown, the box isn't wide enough to show the full item.
Is there any way of changing this? I would prefer to NOT use VBA if possible..
I look forward to your responses :)
There is no possible way to achieve this W/O VBA. if you wish to use VBA solution, then please find code below. You have to paste this code to your Worksheet module, not Regular module, and adjust based on comments.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "$H$1" Then 'adjust this range to your drop down list
Target.Columns.ColumnWidth = 30 'adjust to your needs
Else
Columns(8).ColumnWidth = 8 'adjust column number to column with drop down values
End If
End Sub
When dropdown is not selected:
Dropdown selected:
I have 2 lists in excel. First one is for searching (i want to have dropboxes), and second list is for data.
In second list I have filtered data. But what I want to do now is filter from parameters given in first list.
How can I transfer filter headers on first page?
I want to select brand on 'Search' list and results will be filtered on 'Rows' list.
I can't think of a way to do this exact thing without VBA. Certainly would love to know if there is a way, so maybe someone else can chime in.
That said, here is a small VBA procedure that will get what you want. It works based off a change in the drop down box for Brand in your Search sheet. Follow steps below to implement:
once in Excel hit Ctrl + F11 on your keyboard. This opens up the VBE
In the Project - VBAProject window in the upper left click the Object referring to the Search sheet
Paste the below code into the big window on the right referring to that sheet.
Make sure to save the file as an .xlsm file (Excel-Macro Enabled File) if using XL2007 or greater.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wksFilter As Worksheet, wks As Worksheet
Dim rngFilter As Range
'replace "A6" with the cell where the Brand dropdown is
If Target.Address = "$A$6" Then
Set wks = Sheets(Target.Parent.Name)
Set wksFilter = Sheets("Rows")
'may need to adjust the number 1 to match the exact location of your Search Column in the rows sheet
wksFilter.UsedRange.AutoFilter 1, wks.Range(Target.Address)
End If
End Sub