populate from drop list with multiple tables

price83

New Member
Joined
Jan 17, 2020
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hi All,

i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on another sheet that relate to the selected drop... is this possible?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
how would you advise to call them, sorry my knowledge isn't great with this


Here is code that I built with the help of this forum to create both drop down lists in the user form as well as open another workbook, manipulate that workbook, save the other workbook with a new name.

Code:
' https://www.wallstreetmojo.com/vba-userform/                                          Very good starting place for User Forms
' https://www.excel-easy.com/vba/userform.html                                          More detailed User Form code examples
' https://www.excel-easy.com/vba/create-a-macro.html#command-button                     Command Button guide
' https://superuser.com/questions/536134/how-do-i-change-the-name-of-a-command-button-in-excel  Edit command button
' https://excelmacromastery.com/vba-user-forms-1/                                       Very detailed User Form guide
Option Explicit

Public FoundMax As Integer ' Group maximum global variable. This is set in the GroupComboBox sub


Private Sub CancelCommandButton_Click()

Unload Me       ' Closed User Form

End Sub

Function DirSelect() As String
    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    DirSelect = sItem
    Set fldr = Nothing
End Function

Private Sub StartCommandButton_Click()
' Should Open Table from test folder
' populate Network field & group number.
' .Value=.Value to clear arrays and keep raw text
' perform Save As .xlsx to local computer

'=====================================
' Set Variables
'=====================================
Dim wb As Workbook      ' Shortcut for workbook
Dim ws As Worksheet     ' Shortcut for worksheet
Dim Network As String   ' Used to name workbook as part of Save As
Dim Group As String     ' Used to name workbook as part of Save As
Dim sFName As String    ' Used to name workbook as part of Save As - Final uniform name
Dim Def As String       ' String used as part of the Save As process
Dim i As Integer        ' Iterator variable
Dim Path As String      ' File save path
Dim screenUpdateState As Variant
Dim statusBarState As Variant
Dim displayPagebreakState As Variant

Path = DirSelect()      ' Call the function for the user to select the save path

    ' ============================================
    ' Get current state of various Excel settings.
    ' ============================================

        screenUpdateState = Application.ScreenUpdating
        statusBarState = Application.DisplayStatusBar
        displayPagebreakState = ActiveSheet.DisplayPageBreaks   ' This is sheet-level only.

    ' ==================================================
    ' Turn off Excel functionality to speed up the code.
    ' ==================================================

        Application.ScreenUpdating = False
        Application.DisplayStatusBar = False
        ActiveSheet.DisplayPageBreaks = False   ' This is sheet-level only.

If NOOptionButton = True Then
    FoundMax = 1
End If
    
For i = 1 To FoundMax
    ' Opens Tabel from ShareNow, currently hardcoded to test folder
    Set wb = Workbooks.Open("https://sharenow.foo.xlsm")
    
    'wb.Application.Visible = True           ' Makes the Table spreadsheet visible
    Set ws = wb.Worksheets("Table")     ' Correct worksheet to activate
    'ws.Visible = xlSheetVisible             ' Should keep Table Formula workbook as the visible workbook and worksheet
    ws.Activate                             ' Marks the correct workbook and worksheet to active status
    ws.Range("a1").Select                   ' Select cell A1, safe cell with zero data.
    
    ws.Cells(1, 3).Value = NetworkComboBox.Value       ' Populate cell C1 with Network chosen from dropdown list
    If NOOptionButton = True Then
        ws.Cells(1, 7).Value = GroupComboBox.Value       ' Populate cell G1 with group number
    Else
        ws.Cells(1, 7).Value = i
    End If
    
    Set wb = ActiveWorkbook                 ' Used as shortcut for Workbook
    Set ws = wb.Worksheets("Table")     ' Worksheets shortcut to read data from Table
        ' Read Cells(row, column).Value and store as variable - C1, Network name
    Network = ws.Cells(1, 3).Value
        ' Read Cells(row, column).Value and store as variable - G1, Group #
    Group = ws.Cells(1, 7).Value
        ' Final output will be in format: table_1.xlsx
    Def = "foo" & stuff & "thing" & otherthing
    
    Call CancelCommandButton_Click      ' Close Command Button Window, seems to hang if not closed
    
    '=====================================
    ' Start Copy/Paste Values only section                  Column D -> H, Rows 3 -> 52
    '=====================================
    ws.Range("D3:H52").Value2 = ws.Range("D3:H52").Value2     ' Sets the value from the array output, clearing the array formula
    
    '=====================================
    ' Fill blanks null vaults with FALSE
    ' Leave IS/M (Row 27) blank
    '=====================================
    
    ' Cells(Row, Column) -> Row 3, Column 5 -> E3
    If IsEmpty(Cells(3, 5)) = True Then
        ws.Range("E12:E26").Value = "FALSE"
        ws.Range("E28").Value = "FALSE"
    End If
    
    ' Cells(Row, Column) -> Row 3, Column 6 -> F3
    If IsEmpty(Cells(3, 6)) = True Then
        ws.Range("F12:F26").Value = "FALSE"
        ws.Range("F28").Value = "FALSE"
    End If
    
    ' Cells(Row, Column) -> Row 3, Column 7 -> G3
    If IsEmpty(Cells(3, 7)) = True Then
        ws.Range("G12:G26").Value = "FALSE"
        ws.Range("G28").Value = "FALSE"
    End If
    
    ' Cells(Row, Column) -> Row 3, Column 8 -> H3
    If IsEmpty(Cells(3, 8)) = True Then
        ws.Range("H12:H26").Value = "FALSE"
        ws.Range("H28").Value = "FALSE"
    End If
    
    '=====================================
    'Start Save As process
    '=====================================
'    sFName = Application.GetSaveAsFilename(InitialFileName:=Def, FileFilter:="Excel Files (*.xlsx), *.xlsx, Macro Enabled Workbook" & "(*.xlsm), *xlsm")
    
'        If sFName <> "False" Then                   ' Checks that sFName has not been cancled
'          If Right(sFName, 4) = "xlsx" Then         ' If saved as *.xlsx this section provides correct file type 51
'             Application.DisplayAlerts = False      ' *.xlsx is no macros enabled
'             ws.SaveAs sFName, 51
'             Application.DisplayAlerts = True       ' Displays all errors from SaveAs
'          ElseIf Right(sFName, 4) = "xlsm" Then     ' If saved as *.xlsm this section provides correct file type 52
'             ws.SaveAs sFName, 52                   ' *.xlsm is macro enabled
'          End If
'        End If
    wb.SaveAs Filename:=Path & "\" & Def, CreateBackup:=False
Next i

          ' ===============================
          ' Return Excel to original state.
          ' ===============================

          Application.ScreenUpdating = screenUpdateState
          Application.DisplayStatusBar = statusBarState
          ActiveSheet.DisplayPageBreaks = displayPagebreakState         ' This is sheet-level only.
Unload Me


End Sub

Private Sub UserForm_Click()
On Error Resume Next
UNMTableForm.Show

End Sub

Private Sub UserForm_Initialize()

' Create dropdown list for Network
' The use of the Me. provides auto-populate to gain access for the
' data contained in tNetworkName table with
' column header Network Name

GroupComboBox.Value = ""

' Set All Groups radial button default NO
NOOptionButton.Value = True

End Sub

Private Sub NetworkComboBox_Change()

Dim FoundCell As Range
Dim ws As Worksheet
Dim i As Integer
Dim rng As String
' Dim FoundMax As Integer  - Now set as global variable

Set ws = ActiveSheet

GroupComboBox.Clear             ' Clear current Group ComboBox

Set FoundCell = ws.Range("A:A").Find(What:=NetworkComboBox.Value) ' Find the cell for the selected network
rng = "B" & FoundCell.Row       ' Build the string for the range of the max value
FoundMax = Range(rng).Value     ' Assign the maximum group number
For i = 1 To FoundMax
    GroupComboBox.AddItem i
Next i

End Sub
 
Upvote 0
looks a bit complex for me im afraid is there an easier formula like a indirect range for text or something like that
 
Upvote 0
Are the tables named the same as the dropdown list?
Also is the table just one column?
 
Upvote 0
Yes

Book1
C
1Comment on overall experience
2No comment
3
4
5Comment on overall experience
6Great environment & people
7Enjoy working with multipe customers across site
8Variety of work but can be frustrating
9
10
11
12
13
14
15
16
17
18Comment on overall experience
19It can get very busy sometimes but client/end users are always polite and friendly.
20
21
22Comment on overall experience
23I really enjoy working on most sites, the only issue is documentation and access.
RAW_Data
 
Upvote 0
these are the collumns with headers

Book1
BE
1SiteComment on overall experience
2
3Multiple
4
5
6
7
8
Data
 
Upvote 0
Ok, In E2 copied down
=IFERROR(INDEX(INDIRECT($B$1),ROW(A1)),"")
 
Upvote 0
im not getting anything from that the box just stays blank
 
Upvote 0
What if you use
=INDEX(INDIRECT($B$1),ROW(A1))
 
Upvote 0
where does this formula reference the comments i need on the other sheet?
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top