Context:
In my company, some assistants fill out an Excel table, which is a users list (First Names, Last name, ID number). After, I use this list with a PowerShell script. But very often the users list is not correctly completed. For example, assistants forget to input ID number... .So i would like help assitants to fill this Excel with data suggestions/autocomplete.
Technical:
In the "Data" sheet, I have all data possible (First Names, Last name, ID number).
With the "Name Manager" I created:
d_FirstName to select the first cell
c_FirstName to select all column,
l_FirstName to apply function: =OFSSET(d_FirstName;0;0;COUNTA(c_FirstName)-1;1)
In "Form" sheet, I created drop-down list with function: =IF(A1<>"";OFSSET(d_FirstName;MATCH(A1&"*";l_FirstName;0)-1;;SUMPRODUCT((MID(l_FirstName;1;LEN(A1))=TEXT(A1;"0"))*1));l_FirstName)
So, when the user types a letter, the drop down list "suggest" a correct FirstName.
Question:
How to adapt the last query, to complete a line with First Name and Last name and ID number corresponding if user type only First Name ?
For example:
If user select a First Name in drop down list, Excel complete the lign with Last name and ID number corresponding .
If user select a ID number in drop down list, Excel complete the lign with Last name and First Name corresponding.
In second time, how to show dropdown list automatically when user type one letter ?
Thank you
You can accomplish this using the combobox's properties and change event. The combobox will take a 1 or 2 dimensional named range or a formula that returns a range as it's RowSource. Here I have the text column set to the 3rd column.
Private Sub cboEmpID_Change()
With cboEmpID
If Not IsNull(.Value) Then
lblEmployee.Caption = .List(.ListIndex, 1) & ", " & .List(.ListIndex, 0)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim ColumnWidths As String
With Worksheets("Sheet1")
ColumnWidths = .Columns(1).Width & ";" & .Columns(2).Width & ";" & .Columns(3).Width
End With
With cboEmpID
.ColumnHeads = True
.ColumnCount = 3
.ColumnWidths = ColumnWidths
.TextColumn = 3
.ListWidth = Range("Sheet1!A:C").Width
.RowSource = "OFFSET(Sheet1!$A$1,1,0,COUNTA(Sheet1!$A:$A)-1,3)"
End With
End Sub
You need making a cascading dependent Excel drop down list.See
Related
I can upload a file if someone tells me how.
Need help replicating a filter as you type on a combo box that is being used at the record level. Example: Instead of having an open text box for the prefix (e.g. Mr. Mrs. Ms. Dr.), I'm using a combo box that looks up from a reference table. I want to be able to type the letter "r" in the combo box and have it filter out Ms. and showing the remaining values. Once I make a selection store the selected value in the Name table.
Issue: When I add a new value in Combo4 the other rows above clear out if they don't match the value I just typed into the cell. Something likely with the RowSource in the below formula. Do I have something out of sequence or a flawed formula?
What I think I'm trying to do:
1) If Prefix value populated w/ value in t_Name THEN show the matching value in t_ref_Prefix
2) If Combo4 is Blank / Null THEN then open Combo4 and show all values in t_ref_Prefix so a value can be selected.
3) If user is typing text into Combo4 THEN filter on change using * on both sides of the typed value.
Option Compare Database
Option Explicit
Private Sub Combo4_Change()
'https://stackoverflow.com/questions/48133260/display-records-in-access-db-combobox-on-any-text-typed-by-user
'test number of characters entered - if greater then 0 then assign rowsource
If Len(Me.Combo4.Text) > 0 Then
'set the rowsource to match user search criteria
Me.Combo4.RowSource = "SELECT * FROM t_ref_Prefix WHERE Prefix LIKE '*" & Me.Combo4.Text & "*'"
'show the search in real-time
Me.Combo4.Dropdown
Else
'set to no
Me.Combo4.RowSource = "SELECT t_ref_Prefix.auto, t_ref_Prefix.prefix, t_ref_Prefix.sort FROM _
t_ref_Prefix ORDER BY t_ref_Prefix.sort, t_ref_Prefix.prefix"
End If
End Sub
You need to set
Combo4.AutoExpand = False
This will do it.
I have created a form that asks for two user inputs, site location and sku. Site location is a drop down and SKU is a text box. Below it there is a textbox which I want to populate based on user input after they hit the "whats my price?" button.user form
I have a matrix of prices with the SKU in column B and the sites across the top in row 1 with their respective prices in the matrix(columns D-H). I have attached a sample of the table. Please note that the "SKU" and "Site" titles will not be in my actual matrix.
pricing table
I need assistance coding the "What's my price?" button in the user form.
I feel as though I would need an if statement using some sort of look up but i'm a little lost as to how to start the code.
Here is what you have to do:
Read the value from the site field;
Read the value from the SKU field;
Display the matching in the Your Price is field, using the following formula:
WorksheetFunction.Index(Range,site field, sku field)
More about WorksheetFunction.Index here:
https://msdn.microsoft.com/en-us/library/office/ff197581.aspx
You need to use Application.Match on the row and the column independently, then get the corresponding cell. Try the following code, but replace the control's names (txtSku, cmbSite) and the sheet's code name (mySheet) with yours.
Sub WhatsMyPrice_Click()
Dim rowNum, colNum
rowNum = Application.Match(txtSku.Value, MySheet.Range("B:B"), 0)
If IsError(rowNum) Then MsgBox "SKU not found": Exit Sub
colNum = Application.Match(cmbSite.Value, MySheet.Rows(2), 0)
If IsError(rowNum) Then MsgBox "Site not found": Exit Sub
txtPrice.Value = MySheet.Cells(rowNum, colNum).Value2
End Sub
I have the following code that produces a multi column combo box in a userform showing the Client and ID. I had to produce both columns as the Client and be listed multiple times but the ID is unique.
i = 2
For Each c In Range("D2", Range("D" & Rows.Count).End(xlUp))
CB_Account.AddItem Cells(i, 4).Value & " : " & Cells(i, 3).Value
i = i + 1
Next
However I'm using the value selected filter a sheet so that I can copy client details to a new sheet and am using the selected value as a variable:
MyAccount = UF_Format.CB_Account.Value
The code is currently falling over because the value in the combobox in a concatenation of two columns. Really I need to pull through just the second value being the ID so my code can filter.
Any help would be much appreciated.
You can declare the variable MyAccount as an array, then split the combo box value using colon as the delimiter. You can then work with the second item of the array.
Sub second_value()
Dim MyAccount() As String
MyAccount = Split(UF_Format.CB_Account.Value, " : ")
Debug.Print MyAccount(1)
End Sub
I have a Data table with an Auto Filter (shown Below).
Sub Tariff_Filter()
Dim columnNumber, tableRow, tableColumn, tableWidth As Integer
Dim tableName, columnName As String
tableName = "Tariff_Table"
columnName = ActiveSheet.Range("A1").Value
'This clears the existing filter
ActiveSheet.ListObjects(tableName).Range.AutoFilter
'Assign some numbers we need to know about the table to check the headers
tableRow = ActiveSheet.ListObjects(tableName).Range.Row
tableColumn = ActiveSheet.ListObjects(tableName).Range.Column
tableWidth = ActiveSheet.ListObjects(tableName).Range.Columns.Count
'If a column title with the specified value does not exist VBA throws an error which we need to catch
On Error GoTo ErrorHandler
'Search through the table column header row to find the specified column and assign the number to columnNumber
columnNumber = Application.WorksheetFunction.Match(columnName, Range(Cells(tableRow, tableColumn), Cells(tableRow, tableColumn + tableWidth)), 0)
'Apply the filter "1" to the found columnNumber
ActiveSheet.ListObjects(tableName).Range.AutoFilter field:=columnNumber, Criteria1:="1"
'Exit the sub otherwise the "error handling" will be provoked
Exit Sub
ErrorHandler:
MsgBox columnName & "Please Specify Required Channel"
End Sub
As i cant seem to figure out how to get my combo-box's to show only the visible cells after filtering the table i was wondering if there is a way i can create a a validation box to show the visible cells or copy the visible data into a seperate table underneath. I can then use the validation box/ secondary table as a focus point for the combo-box's on the user-form.
Thanks in advance
If I'm understanding your question correctly, you would like to have a data-validation drop-down list that updates as the table is filtered and only displays visible items for a given column.
You can do this by using the following formula in Data Validation (I'm assuming your table header row starts in A1 and it's col A you need to display):
=OFFSET($A$2,,,SUBTOTAL(103,TableName[column name]))
This formula expands from the starting cell (A2) by a specified height in number of rows. We are defining the height using SUBTOTAL with function number 103 - this means that the height is defined using COUNTA, but only on visible cells, so it will expand and collapse as the table is filtered.
Be aware: since the height is defined using a counta function, it will only count cells containing data, therefore if you have blanks in your table, the range will not be defined correctly. Also if you have any repeated data, these will be repeated in your drop-down box, this method will not condense them into a neat, unique list.
Hope this is helpful.
D
In combobox I set columnCount to 3, so when I click dropdown arrow I can see 3 columns that I need, but when I choose one row that I need, there is only value from first column shown. Combobox is wide enough for all three columns. Is there a way to see all 3 when I select my choice?
You need to change the ListFillRange to all the columns in your list:
Sheet1!$A$5:C20
Also you need to have a single cell referenced in the LinkedCell property: Sheet1!$A$1
The bound column must be a value between 1 and 3. You can only return a single value from the list - this will be from the bound column.
Your column count must be 3.
Your column widths must be either blank or a value >0 (0 will hide the column):
85.05 pt;85.05 pt;85.05 pt
With those in place you should be seeing three columns of values in the list box - you can only return a value from one of those columns though.
If you want to return more than one I'd suggest using a hidden (column width of 0) column to contain a unique identifier and then use a look-up on the sheet to fill in the blank columns.
To get to all three columns in VBA use code similar to:
Private Sub ComboBox1_Change()
With Me.ComboBox1
MsgBox .Column(0) & vbCr & .Column(1) & vbCr & .Column(2)
End With
End Sub