Solved

Using an Index number to generate a table in excel?

Posted on 2011-03-22
5
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

726 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