+ Reply to Thread
Results 1 to 18 of 18

Find Column Number and then use Index Function

Hybrid View

  1. #1
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Find Column Number and then use Index Function

    I have a database with over 100 products listed across the first row.
    Column a has a list of over 500 projects. Across each project various columns are marked with a number depending on how many of each products are being used on that project.
    For Example

    A B C D E etc.
    Products --> X Y Z AA
    Proj 1 2 3
    Proj 2 1 4 5
    Proj 3 2 4
    etc.

    I want to be able to create a report for any given product.
    The report could look like,
    Product Z
    Proj 1 3
    Proj 3 2

    So I need to lookup the product code across row 1 and determine the column number and then INDEX down that column and find all non blank cells and read the project names from column A.

    Thanks in advance for any help.
    I am familiar with formulas with INDEX and V/H LOOKUP functions. I am not very good with VBA codes.

    modytrane

  2. #2
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Find Column Number and then use Index Function

    Sorry about the formating of the example above.

    Here's a better example:

    Products ---->____X_____Y_____Z_____AA
    Proj 1____________2_____3_____0_____ 0
    Proj 2____________0_____1_____3_____1
    Proj 3____________4_____0_____2_____4

    Report:
    Product Z______Qty.
    Proj 2__________3
    Proj 3__________2

    Hope this makes it more clear.

    Thanks,
    modytrane

  3. #3
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Lookup Column Number and Index Down that Column

    Can someone please help me get started on this problem?
    I need a formula to search for a text string across a ROW and find the column number [or letter]. Then I need to look down that column and find any non blank cells [and its row number]. Then look across that row to pick out values from various columns across that row to generate a report.
    The example I gave in my previous message is a very basic. Once I get that figured out, I can write more complex ones with many more fields and search criteria.

    Thanks.
    mondytrane

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to attach an example workbook. I would suggest that you zip it first
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Find Column Number and Index that column

    Here's a workbook.
    Its a small portion of a larger workbook with example of a report on sheet2.
    Thanks for your help.
    modytrane
    Attached Files Attached Files

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See attached:

    Your example with my formulas applied....
    Attached Files Attached Files
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485
    Try this

    Data in A1:E4
    Reporting product in B9

    Output starts A11

    Sub x()
    
        Dim rngData As Range
        Dim rngProduct As Range
        Dim lngRow As Long
        Dim rngOutput As Range
        Dim lngCol As Long
        
        Set rngData = Range("B1").CurrentRegion
        Set rngProduct = Range("B9")
        
        lngCol = Application.WorksheetFunction.Match(rngProduct, rngData.Rows(1), 0)
        
        Set rngOutput = Range("A11")
        rngOutput.CurrentRegion.Clear
        
        For lngRow = rngData.Rows(1).Row + 1 To rngData.Rows(1).Row + rngData.Rows.Count - 1
            If rngData.Cells(lngRow, lngCol) > 0 Then
                rngOutput.Cells(1, 1) = rngData.Cells(lngRow, 1)
                rngOutput.Cells(1, 2) = rngData.Cells(lngRow, lngCol)
                Set rngOutput = rngOutput.Offset(1)
            End If
        Next
        
    End Sub
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See attached:

    Formulas in Sheet2:

    In A3:
    =IF(ROWS($A$1:$A1)>SUMPRODUCT((Sheet1!$B$1:$E$1=$B$1)*(Sheet1!$B$2:$E$4>0)),"",INDEX(Sheet1!$A$2:$E$4,SMALL(IF(Sheet1!$B$1:$E$1=$B$1,IF(Sheet1!$B$2:$E$4>0,ROW(Sheet1!$A$2:$A$4)-ROW(Sheet1!$A$2)+1)),ROWS($A$1:$A1)),1))
    in A4:
    =IF(ROWS($A$1:$A1)>SUMPRODUCT((Sheet1!$B$1:$E$1=$B$1)*(Sheet1!$B$2:$E$4>0)),"",INDEX(Sheet1!$A$2:$E$4,SMALL(IF(Sheet1!$B$1:$E$1=$B$1,IF(Sheet1!$B$2:$E$4>0,ROW(Sheet1!$A$2:$A$4)-ROW(Sheet1!$A$2)+1)),ROWS($A$1:$A1)),MATCH($B$1,Sheet1!$A$1:$E$1,0)))
    both formulas confirmed with CTRL+SHIFT+ENTER not just ENTER and then copied down.

    If you make changes reconfirm with CSE before copying down.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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