Hello There,
I would like to see if the below requirement is possible to achieve using VBA. The requirement is to have a ListBox which is based on an Excel table. The User will pass the Table Name and the Table Column Names(x) which will be used to build the ListBox using Array.
With my little VBA knowledge, I find it a challenging one. Really look forward to see this working.
I have attached a sample workbook for your reference.
Look forward to hearing from you.
Many thanks & regards,
Don
Requirement:
------------------------------------------------------------------------------------------------
Bring Select Table Columns into ListBox using Array with Search Functionality
------------------------------------------------------------------------------------------------
The Program will have a Sub with parameters TableName and TableColumnNames to be listed in the ListBox with max 5 TableColumNames
Eg. Sub BuildListBox(TableName, ColumnName1, ColumnName2, Columnname3, ColumnName4, ColumnName5)
------------------------------------------------------------------------------------------------
Call BuildListBox( TableName = "Tbl_Currency"
ColumnName1 = "Currency Code"
ColumnName2 = "Currency Name" )
The other ColumnName parameters will have default empty value
------------------------------------
Below logic for Sub BuildListBox
------------------------------------
Step 1. Based on the sub BuildListBox parameters ColumnName(x), build Array with that many columns
Step 2. In this case: Columns to be selected from Table "Tbl_Currency" for ListBox
-Currency Code and Currency Name
Step 3. The above Step 1 selection of columns will define number of columns Array will have
Step 4. On Load UserForm1:
- Perform Step 1, 2 & 3
- Using the parameter TableName, display all Data and the Column Header in the Listbox
- Adjust the column widths
Step 5. On button "Search" with some string entered eg. "upee":
- Step 1, 2 & 3: Array is already loaded with all data
- Search Array for the "Search String Value"
- If found, display all the records which satisfy the search string in the Listbox
- eg. if Search String = "upee", then it should list all rows from Array where string = "rup"
ListBox will show 3 rows:
1. 'Indian Rupee'
2. 'Pakistani 'Rupee'
3. 'Indonesian Rupiah'
Step 6. On button pressed "OK"
- From the ListBox, it should display the values to the worksheet:
Range("FCurrencyCode) = ListBox.FirstColumn.value
Range("FCurrencyNamee) = ListBox.Second.value
- Clear the Array
Step 7. On button pressed "Cancel"
- Clear the Array
I would like to see if the below requirement is possible to achieve using VBA. The requirement is to have a ListBox which is based on an Excel table. The User will pass the Table Name and the Table Column Names(x) which will be used to build the ListBox using Array.
With my little VBA knowledge, I find it a challenging one. Really look forward to see this working.
I have attached a sample workbook for your reference.
Look forward to hearing from you.
Many thanks & regards,
Don
Requirement:
------------------------------------------------------------------------------------------------
Bring Select Table Columns into ListBox using Array with Search Functionality
------------------------------------------------------------------------------------------------
The Program will have a Sub with parameters TableName and TableColumnNames to be listed in the ListBox with max 5 TableColumNames
Eg. Sub BuildListBox(TableName, ColumnName1, ColumnName2, Columnname3, ColumnName4, ColumnName5)
------------------------------------------------------------------------------------------------
Call BuildListBox( TableName = "Tbl_Currency"
ColumnName1 = "Currency Code"
ColumnName2 = "Currency Name" )
The other ColumnName parameters will have default empty value
------------------------------------
Below logic for Sub BuildListBox
------------------------------------
Step 1. Based on the sub BuildListBox parameters ColumnName(x), build Array with that many columns
Step 2. In this case: Columns to be selected from Table "Tbl_Currency" for ListBox
-Currency Code and Currency Name
Step 3. The above Step 1 selection of columns will define number of columns Array will have
Step 4. On Load UserForm1:
- Perform Step 1, 2 & 3
- Using the parameter TableName, display all Data and the Column Header in the Listbox
- Adjust the column widths
Step 5. On button "Search" with some string entered eg. "upee":
- Step 1, 2 & 3: Array is already loaded with all data
- Search Array for the "Search String Value"
- If found, display all the records which satisfy the search string in the Listbox
- eg. if Search String = "upee", then it should list all rows from Array where string = "rup"
ListBox will show 3 rows:
1. 'Indian Rupee'
2. 'Pakistani 'Rupee'
3. 'Indonesian Rupiah'
Step 6. On button pressed "OK"
- From the ListBox, it should display the values to the worksheet:
Range("FCurrencyCode) = ListBox.FirstColumn.value
Range("FCurrencyNamee) = ListBox.Second.value
- Clear the Array
Step 7. On button pressed "Cancel"
- Clear the Array