+ Reply to Thread
Results 1 to 11 of 11

INDEX/Match help (VBA eventually)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-11-2016
    Location
    Atlanta
    MS-Off Ver
    2016
    Posts
    104

    INDEX/Match help (VBA eventually)

    I'm posting this in the VBA section because ultimately I will use VBA to do this but I believe if someone could just help me with a normal function I can translate it to a VBA "For" statement myself.

    A user enters a number in the message box and this value is stored in AuctionNum. I believe the number is entered into the table as type general.

    AuctionNum = Application.InputBox("Please enter the auction number", "Next Auction Data", Type:=1)
    I then need to use this number to look up several sets of data within a table. The AuctionNum occurs in column C, but there are several different AuctionNums within the table. So anytime the entered AuctionNum occurs, I need to pull data from the corresponding row. The main data I need is the WorkOrder Number which occurs in column A. I also need to grab the Car Year (col G), Car Make (col H), the seller( col E), and the body (col L).

    I set up a table to place the values that are pulled. So every data point in this new table will have an AuctionNum of whatever number is entered by the user.

    Auction Num WorkOrder Car Year Car Make Seller Body


    'AuctionCars is the number of cars in the current auction 
    For i = 1 to AuctionCars 
         ws4.Cells(i, "A").Value = AuctionNum
         ws5.Cells(i,"B").Value  = 'would be equal to the first work order that has a match of AuctionNum
    Next i
    Placing this data in a 2-D array would help me as well because eventually I need an array with the WO number in column 1 and the Body Type in column 2.

    Here's the formula (not code) I tried to use but it doesn't work. I think it just grabs every single WO number from column A
    Formula: copy to clipboard

    =INDEX('Manheim Car Data'!A2:$A$565, MATCH(B3, 'Manheim Car Data'!$C$2:$C$565, 0))

    B3 contains the correct auction number (i.e. if there are 50 cars to be sold in auction 39, then 39 is pasted 50x in the column) and the data table with all of the auction data is titled 'Mannheim Car Data'

    I feel like I started to ramble because I wanted it to make sense but i'll be on my computer if there's any questions.

    Thanks for the help,

    Matt
    Last edited by Leith Ross; 11-25-2016 at 07:26 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: INDEX/Match help (VBA eventually)

    Hello Matt,

    You should post a copy of your workbook.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    06-11-2016
    Location
    Atlanta
    MS-Off Ver
    2016
    Posts
    104

    Re: INDEX/Match help (VBA eventually)

    Ok here is my file.

    Edit:

    Hit the run button Daily Auction sheet tab, type in 39. Next I am pulling all of the data from the rows that contain auction 39 from the Mannheim Auction Data tab. Then, I am filling in the Current Auction Database with the pulled data.
    Attached Files Attached Files
    Last edited by Buzz1126; 11-25-2016 at 08:32 PM.

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: INDEX/Match help (VBA eventually)

    Similar thread in the Formulas/Functions forum...

    https://www.excelforum.com/showthread.php?t=1164682
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Forum Contributor
    Join Date
    06-11-2016
    Location
    Atlanta
    MS-Off Ver
    2016
    Posts
    104

    Re: INDEX/Match help (VBA eventually)

    That's me also! Posted it in the other place to get help with excel in general. I then posted it here too to get help with the VBA part of it.

    So here is the question simplified,

    I need to grab all the WO (in col. A) that have an auction number of 39 (in col. C) and place the values in an array. Just a simple list of the WO that are going to be in auction 39.

  6. #6
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: INDEX/Match help (VBA eventually)

    hahah oops I didn't read the above post that cleared up all my questions

  7. #7
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: INDEX/Match help (VBA eventually)

    just taking a quick look at this, where is the input box or where would you like it to be for the user to input the sale# into to start and retrieve all the data? also is all this data supposed to be shown on the current data sheet?

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: INDEX/Match help (VBA eventually)

    A lot different approach but here is my example of filling in the Current Auction Data Sheet

    Option Explicit
    
    Type CurrentAuction
        AuctionNum As Integer
        SaleYear As Long
        CarID As String
        Seller As String
        CarType As String
        ETA As String
        Lane As Integer
    End Type
    
    Const shManheimCarData As String = "Manheim Car Data"
    Const shDailyAuction As String = "Daily Auction Sheet"
    Const shDatabase As String = "Database"
    Const shData As String = "Data"
    Const shCurrentAuction As String = "CurrentAuctionData"
    Const shHidden As String = "Hidden"
    
    Sub abcButtonPress()
     Dim NewCurrentAction() As CurrentAuction
     Dim AuctNumber As Integer
     Dim arrManCarData As Variant
     Dim i As Long
     
        'prompts the user to enter the auction number then stores it in the variable AuctionNum,
        'the value is then placed in cell c6 of the workbook
        AuctNumber = Application.InputBox("Please enter the auction number", "Next Auction Data", Type:=1)
        '*******************
        If AuctNumber = 0 Then Exit Sub 'User Canceled
        '*******************
        
        
        With Worksheets(shManheimCarData)
            arrManCarData = .Range("a1").CurrentRegion.Value
        End With
        
        ReDim NewCurrentAction(0)
        For i = 1 To UBound(arrManCarData)
            If arrManCarData(i, 3) = AuctNumber Then
                With NewCurrentAction(UBound(NewCurrentAction))
                    .AuctionNum = AuctNumber
                    .SaleYear = arrManCarData(i, 2)
                    .CarID = arrManCarData(i, 1)
                    .Seller = arrManCarData(i, 5)
                    .CarType = arrManCarData(i, 12)
                    .Lane = arrManCarData(i, 4)
                End With
                ReDim Preserve NewCurrentAction(UBound(NewCurrentAction) + 1)
            End If
        Next
        
        If UBound(NewCurrentAction) > 0 Then
            ReDim Preserve NewCurrentAction(UBound(NewCurrentAction) - 1)
            With Worksheets(shCurrentAuction)
                .Range("a3", .Cells(Rows.Count, "b").End(xlUp).Offset(1).Resize(, 7)).ClearContents
                For i = 0 To UBound(NewCurrentAction)
                    .Cells(i + 3, "A") = i + 1
                    .Cells(i + 3, "B") = NewCurrentAction(i).AuctionNum
                    .Cells(i + 3, "C") = NewCurrentAction(i).SaleYear
                    .Cells(i + 3, "D") = NewCurrentAction(i).CarID
                    .Cells(i + 3, "E") = NewCurrentAction(i).Seller
                    .Cells(i + 3, "F") = NewCurrentAction(i).CarType
                    .Cells(i + 3, "G") = NewCurrentAction(i).ETA
                    .Cells(i + 3, "H") = NewCurrentAction(i).Lane
                Next
            End With
            With Worksheets(shDailyAuction)
                .Cells(8, "C") = AuctNumber
                .Cells(11, "C") = UBound(NewCurrentAction) + 1
            End With
        End If
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  9. #9
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: INDEX/Match help (VBA eventually)

    I did this using an advanced filter but for some reason the site will not allow me to upload it so heres the code, you will have to change on work sheet "currentauction", swap columns G and H around

    Option Explicit
    
    Sub ButtonPress()
        
        Dim RowMatch As Variant      'Row number of the matched Auction Number
        Dim AuctionNum As Integer    'the auction number
        Dim AuctionCars As Integer    'number of cars in the inputed auction
        Dim AuctionSeller As String    'company selling the cars
        Dim SaleYear As String         'auction year pulled from manheim car database
        Dim IRange As Range
        Dim ORange As Range
        Dim Crange As Range
        Dim CarTimeArray() As String  '2-D array (WO, car completion time)
        Dim arrayRng As Range         'the range in which the CarTimeArray() is stored
    
        Dim i, j, k, FinalRow As Integer        'declaration variables for loops
        
        Dim ws1, ws2, ws3, ws4, ws5, ws6 As Worksheet
        Set ws1 = ThisWorkbook.Sheets("Daily Auction Sheet")
        Set ws2 = ThisWorkbook.Sheets("Database")
        Set ws3 = ThisWorkbook.Sheets("Data")
        Set ws4 = ThisWorkbook.Sheets("CurrentAuctionData")
        Set ws5 = ThisWorkbook.Sheets("Hidden")
        Set ws6 = ThisWorkbook.Sheets("Manheim Car Data")
        
        'prompts the user to enter the auction number then stores it in the variable AuctionNum,
        'the value is then placed in cell c6 of the workbook
        AuctionNum = Application.InputBox("Please enter the auction number", "Next Auction Data", Type:=1)
    
        '*******************
        If AuctionNum = 0 Then Exit Sub 'User Canceled
        '********************
    
        'Finds the AuctionNumber and stores it in a variable
        ws1.Range("C8").Value = AuctionNum
        
        'Match Auction Number and return the row number of 1st match
        RowMatch = Application.Match(AuctionNum, ws6.Range("C:C"), False)
        
        'places information on the current auction in the appropriate cells
        If Not IsError(RowMatch) Then   'Test if match was found
            SaleYear = ws6.Range("B" & RowMatch).Value 'Return Value from column B of the matched row
            ws1.Range("C9").Value = SaleYear
    
            '*** Taken out because different sellers per auction****
            'AuctionSeller = ws2.Range("D" & RowMatch).Value 'Return Value from column D of the matched row
            'ws1.Range("C10").Value = AuctionSeller
    
            AuctionCars = Application.CountIf(ws6.Range("C:C"), AuctionNum) 'Count rows that have the auction number
            ws1.Range("C11").Value = AuctionCars
            
             
      '*****ADVANCED FILTER******
    FinalRow = ws6.Cells(Rows.Count, 1).End(xlUp).Row
    
    'set criteria range
    ws1.Cells(7, 3).Value = ws6.Cells(1, 3).Value
    Set Crange = ws1.Range("c7:c8")
    
    'add header and set output range
    ws4.Range("b2:g2").Value = Array(ws6.Cells(1, 3), ws6.Cells(1, 7), ws6.Cells(1, 1), ws6.Cells(1, 5), ws6.Cells(1, 12), ws6.Cells(1, 4))
    Set ORange = ws4.Range("B2:g2")
    
    'Input range
    Set IRange = ws6.Range("a1").Resize(FinalRow, 12)
    
    'do the advanced filter
    IRange.AdvancedFilter xlFilterCopy, Crange, ORange
    
    'erase all background color
    ws4.Range("a1").CurrentRegion.Interior.ColorIndex = xlNone
            
            
            
        Else
            MsgBox "No match found for " & AuctionNum, , "Auction Number Not Found"
            ws1.Range("C8:C11").ClearContents
    
        End If
    
        'sets up the current auction database
      '  For i = 3 To AuctionCars + 2
            '*********Need to clear contents before updating***
    
          '  ws4.Cells(i, "B").Value = AuctionNum
           ' ws4.Cells(i, "C").Value = SaleYear
            'ws4.Cells(i, "D").Value = Application.WorksheetFunction.Vlookup(ws4.Cells(i, "B").Value, ws6.Range("
            'ws4.Cells(i, 5).Value = ws2.Cells(i, 5).Value 'Car type
            'ws4.Cells(i, 6).Value = ws2.Cells(i, 6).Value 'Car ID
            'adds the eta for each type of car in column 7 of the CurrentAuctionDatabase
            'ws4.Cells(i, 7).Value = Application.WorksheetFunction.VLookup(ws4.Cells(i, 5).Value, ws3.Range("B3:C6"), 2, False)
       ' Next i
    
    
        'Sets up the Array CarTimeArray (A 2-D array with times of each car)
        '(Work order number, Car completion Times)
        ReDim CarTimeArray(1 To AuctionCars, 1 To 2)
        For i = 1 To AuctionCars
            CarTimeArray(i, 1) = ws4.Cells(i + 2, 6).Value
            CarTimeArray(i, 2) = ws4.Cells(i + 2, 7).Value
        Next i
    
    
        'pastes the array in the hidden tab (ws5) to test the values
        For i = 1 To AuctionCars
            ws5.Cells(i + 1, 2).Value = CarTimeArray(i, 1)
            ws5.Cells(i + 1, 3).Value = CarTimeArray(i, 2)
        Next i
    
        'Sorts the CarTimeArray in descending order (highest to lowest times)
        
       
    
        'sets up which lane the cars go into in a table
        'For j = 3 To AuctionCars + 2
         '   For k = 9 To 14
          '      ws4.Cells(j, 8).Value = Application.WorksheetFunction.Match(Application.WorksheetFunction.Min(ws4.Range("I2:N2")), ws4.Range("I2:N2"), 0)
                
    
           ' Next k
        'Next j
        
    
        
    End Sub

  10. #10
    Forum Contributor
    Join Date
    06-11-2016
    Location
    Atlanta
    MS-Off Ver
    2016
    Posts
    104

    Re: INDEX/Match help (VBA eventually)

    Thank you both so much for the help. Sorry I'm late getting back to y'all as it was my birthday yesterday (and I'm in college haha). Running through everything now.

    Matt

  11. #11
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: INDEX/Match help (VBA eventually)

    If any of our posts helped you please mark as solvef

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] INDEX+MATCH instead of VLOOKUP+MATCH, why is INDEX a better choice and how to re-write?
    By Renejorgensen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2016, 10:54 AM
  2. [SOLVED] Index / Match - match 3 input values and return the results from the index
    By t83357 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-08-2016, 07:34 PM
  3. [SOLVED] Match-Index in stead of Index-Match lookup Array among Arrays
    By Numnum in forum Excel General
    Replies: 2
    Last Post: 10-15-2015, 02:08 PM
  4. Replies: 6
    Last Post: 04-30-2014, 02:42 AM
  5. Replies: 6
    Last Post: 11-08-2013, 10:29 PM
  6. INDEX/MATCH function eventually changed the location of the source file
    By seimeion1208 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-30-2013, 07:07 AM
  7. Replies: 3
    Last Post: 05-02-2013, 01:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1