Solved

Using an Index number to generate a table in excel?

Posted on 2011-03-22
5
345 Views
Last Modified: 2013-11-27
I have a combo box (combo box 1) which is currently linked to cell A1 in a given sheet.

A1 is showing an index number that changes when the value of the combo box changes.

I have another sheet in the same workbook that has a table using this index.

it has 1000's of rows and x number of columns.

I'd like to show a table of each row that has this index on the same sheet that has the combo box.

0
Comment
Question by:sanjangeorge
  • 3
5 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35193312
May I see a sample file so that I can get my references correct?

Sid
0
 

Author Comment

by:sanjangeorge
ID: 35193378
Here you go Sid
ExampleForTables.xls
0
 
LVL 4

Expert Comment

by:MeLindaJohnson
ID: 35193526
Could you do this as a pivot table?
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35193527
The code is almost ready. Quick question. Will there be duplicates values in Sheet1?

Sid
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 35193582
If there won't be duplicate values then try this :)

Sample File Attached. All you need to do is manually change the values in Cell A1

Sid

Code Used

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim i As Long, ws1LastRow As Long, ws2LastRow As Long
        Dim matchIndex As String, AllCars As String
        
        On Error GoTo Whoa
        
        Set ws1 = ActiveSheet
        Set ws2 = Sheets("Sheet1")
        ws2LastRow = ws2.Range("A" & Rows.Count).End(xlUp).Row
        
        ws1.Range("A12:E" & Rows.Count).ClearContents
        
        matchIndex = Target.Value
        
        With ws2
            .Range("$A$1:$E$" & ws2LastRow).AutoFilter Field:=1, Criteria1:=matchIndex
            .UsedRange.Offset(1, 0).Resize(.UsedRange.Rows.Count - 1).Rows.Copy _
            ws1.Range("A12")
            .Range("$A$1:$E$" & ws2LastRow).AutoFilter
        End With
        
        ws1LastRow = ws1.Range("B" & Rows.Count).End(xlUp).Row
        
        For i = 12 To ws1LastRow
            AllCars = AllCars & ", " & ws1.Range("C" & i).Value
        Next i
        
        ws1.Range("G3").Value = Mid(AllCars, 2)
    End If
LetsContinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume LetsContinue
End Sub

Open in new window

Index-Numbers.xls
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now