+ Reply to Thread
Results 1 to 13 of 13

Macro help, for look up and index?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Question Macro help, for look up and index?

    GOOD MORNING,
    I have a combination list and in col “A” a data which each number have a values of two array numbers what I would like is to have a macro to lookup and index combination list according to
    The values of each number in data. If you are confused with my explanation please look to my attachment workbook.thanks and very much appreciate any help and suggestion.
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: Macro help, for look up and index?

    Try this and copy it down.

    =VLOOKUP(LEFT(C2,2),$A$2:$B$11,2,FALSE)&","&VLOOKUP(MID(C2,4,2),$A$2:$B$11,2,FALSE)&","&VLOOKUP(RIGHT(C2,2),$A$2:$B$11,2,FALSE)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: Macro help, for look up and index?

    Thanks Alan,
    but i'm getting "N"/A" error with this formula.very sorry for being pain, but my list more than 2000 rows i would rather use vb code if you dont mind.
    Thanks again and very much appreciate your help.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: Macro help, for look up and index?

    Here is some code that works for me, if you make the change to Column A as advised.

    Sub foo()
    
    '  Code developed by ASidman 11/11/13
    
        Dim lr As Long
        lr = Range("C" & Rows.Count).End(xlUp).Row
        Dim lra As Long
        lra = Range("B" & Rows.Count).End(xlUp).Row
        Dim i As Long
        Range("D2:D" & lr).FormulaR1C1 = "=VLOOKUP(LEFT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(MID(RC[-1],4,2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(RIGHT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)"
        
    End Sub
    Attached Files Attached Files
    Last edited by alansidman; 11-11-2013 at 10:33 PM. Reason: added spreadsheet attachment.

  5. #5
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: Macro help, for look up and index?

    Alan,
    Thanks very very much for your invaluable help,the code and formula works perfect for me.
    have a very good day or Night??

  6. #6
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: Macro help, for look up and index?

    Hi,
    Just curious if I have 4 numbers in column “C” what would be the formula change?
    I done one minor change to the formula evenso it working but with wrong result?
    DATA COMB.LIST
    01 10 13 01 02 03 04 10 13 ,11 22,11 22,16 23
    02 11 22 01 02 04 05 10 13 ,11 22,11 22,09 28
    03 15 30 01 02 05
    04 16 23 01 02 06
    =VLOOKUP(LEFT(C2,2),$A$2:$B$11,2,FALSE)&","&VLOOKUP(MID(C2,4,2),$A$2:$B$11,2,FALSE)&","&VLOOKUP(MID(C2,4,2),$A$2:$B$11,2,FALSE)&","&VLOOKUP(RIGHT(C2,2),$A$2:$B$11,2,FALSE)
    thanks

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: Macro help, for look up and index?

    My apologies. I was, too. I forgot to mention to get this to work, you need to have column A as text. With your current set up you have column A as a number and column C as text. You will need to change column A to text. .ie, '01, '02, etc. This can easily be converted to VBA, but you will need to fix column A to make it work in that environment also. Give me a few minutes to write up some VBA code.

  8. #8
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: Macro help, for look up and index?

    Hi Alan,
    Very much appreciate your time, i changed column A to text still i got "N/A" error .??
    Kind regards

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: Macro help, for look up and index?

    Would you always have four numbers or could it be mixed, some rows with four and some rows with three?

    This will make a big difference in how the VBA is written because if it is mixed, then the code will need to test for the length of the string and decide on the formula to apply. In either case, it can be accomplished.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: Macro help, for look up and index?

    Assuming you have a mixed bag of numbers, then you would use this code:

    Sub foo()
        Dim lr As Long
        lr = Range("C" & Rows.Count).End(xlUp).Row
        Dim lra As Long
        lra = Range("B" & Rows.Count).End(xlUp).Row
        Dim i As Long
            For i = 2 To lr
                If Len(Range("C" & i)) > 10 Then
                    Range("D" & i).FormulaR1C1 = "=VLOOKUP(LEFT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(" & _
                    "MID(RC[-1],4,2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""& vlookup(" & _
                    "mid(RC[-1],7,2),R2C1:R[" & lra & "]C2,2,False)&"",""& VLOOKUP(" & _
                    "RIGHT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)"
                Else
                    Range("D" & i).FormulaR1C1 = "=VLOOKUP(LEFT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(" & _
                    "MID(RC[-1],4,2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&  VLOOKUP(" & _
                    "RIGHT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)"
                End If
            Next i
    End Sub
    Last edited by alansidman; 11-12-2013 at 12:20 PM.

  11. #11
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: Macro help, for look up and index?

    Thanks Alan,
    before i had the chance to tell you what i have in column "C",you come up with nice code ,very ..........very much appreciated.
    but in any case what would be the vlookup formula if column have 4 numbers only?the reason i'm asking is to learn how to change the formula?
    Thanks again
    sem

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: Macro help, for look up and index?

    Here is the solution to the last question

    Sub foo()
        Dim lr As Long
        lr = Range("C" & Rows.Count).End(xlUp).Row
        Dim lra As Long
        lra = Range("B" & Rows.Count).End(xlUp).Row
        Dim i As Long
        Range("D2:D" & lr).FormulaR1C1 = "=VLOOKUP(LEFT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(" & _
        "MID(RC[-1],4,2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(" & _
        "MID(RC[-1],7,2),R2C1:R[" & lra & "]C2,2,FALSE)&"",""&VLOOKUP(" & _
        "RIGHT(RC[-1],2),R2C1:R[" & lra & "]C2,2,FALSE)"
        
    End Sub

  13. #13
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: Macro help, for look up and index?

    Hi Alan,
    I can not thank you enough for your time and invaluable help very much appreciated.
    by experimenting with your formula,now it would work even if i have 6 or 7 numbers in column "C"..
    Very Kind Regards
    Sem

+ 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. Macro or Index/Match?
    By ytrehguodleinad in forum Excel General
    Replies: 2
    Last Post: 06-06-2012, 11:00 PM
  2. [SOLVED] INDEX / MATCH or do I need a Macro?
    By reece in forum Excel General
    Replies: 7
    Last Post: 05-10-2012, 09:00 PM
  3. macro for index, match
    By psrs0810 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2010, 05:30 AM
  4. Macro to add index entries
    By hutch@edge.net in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2009, 12:02 PM
  5. Macro for INDEX MATCH
    By hannes in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2005, 06:09 PM

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