VBA Find and Return Table name from Dropdown Selection.

Falko26

Board Regular
Joined
Oct 13, 2021
Messages
89
Office Version
  1. 365
Platform
  1. Windows
Hey Team,

I have a Dropdown list in Range("I1") that represents all Table Headers shown in Column B. What I would like to do is select one of the Table Headers from the dropdown list then run a VBA Macro to search column B for said Header. Once found and selected then offset selection down into the table and return the Table Name (List Object) of current selection to Range("J1").

Anyone have any ideas on how to do that?

1651507067676.png
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
try this in a regular module

VBA Code:
Function TableName() As String
    Dim tbl
    For Each tbl In ActiveSheet.ListObjects
        With tbl
            If Not Intersect(.Range, Selection(2, 1)) Is Nothing Then
                TableName = .Name
                Exit Function
            End If
        End With
    Next
End Function

and this in your worksheet module:

VBA Code:
Private Sub Worksheet_Change(ByVal TableTitle As Range)
    If TableTitle.Address <> "$I$1" Then Exit Sub
    Dim x As Range
    Set x = [B:B].Find(What:=TableTitle, After:=[B1], LookIn:=xlFormulas2, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False)
    If Not x Is Nothing Then
        x.Select
        [j1] = TableName()
        ActiveWindow.ScrollRow = Selection.Row
    Else
        MsgBox "Not found: " & TableTitle
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,820
Members
448,990
Latest member
rohitsomani

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