+ Reply to Thread
Results 1 to 3 of 3

Vlookup with for each

Hybrid View

  1. #1
    Registered User
    Join Date
    03-04-2017
    Location
    norway
    MS-Off Ver
    2016
    Posts
    41

    Vlookup with for each

    Hello! I have a code where I need to use Vlookup. In Workbook nr. A I have one row with names, then one row next to it with numbers. In workbook nr. B I have named each sheet with the names from workbook A. I would like to loop through all sheets in workbook nr. B and use vlookup/match and set the matched number in column B(next to the names). Code:
    Names is in column A, workbook nr. A, numbers in column B.

    Sub nwid()
    Dim ws As Worksheet

    For Each ws In Workbooks("Handel lister.xlsx").Worksheets
    Range("B1").FormulaR1C1 = _
    "=VLOOKUP(RC[-1],[Aksjer.xlsm]Nummerering!C1:C2,2,TRUE)"
    Next ws

    End Sub
    Really hope someone is able to help.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,853

    Re: Vlookup with for each

    Sub nwid()
    Dim ws As Worksheet
    
    For Each ws In Workbooks("Handel lister.xlsx").Worksheets
        ws.Range("B1").FormulaR1C1 = _
             "=VLOOKUP(RC[-1],[Aksjer.xlsm]Nummerering!C1:C2,2,TRUE)"
    Next ws
    
    End Sub
    But that isn't going to work because the lookup range is only two cells, both in column C, hence you can't return data from the second column.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-04-2017
    Location
    norway
    MS-Off Ver
    2016
    Posts
    41

    Re: Vlookup with for each

    Thank you for the reply! The Vlookup works properly, but it does not work as a loop or for each.

+ 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. Replies: 5
    Last Post: 12-07-2016, 09:18 AM
  2. Replies: 0
    Last Post: 12-26-2013, 01:12 PM
  3. Display Cell within VLookup range that excel thinks matches the VLookup Value
    By headachexcelperson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-04-2013, 04:56 PM
  4. [SOLVED] Vlookup is not working and giving =vlookup(B2,$T$2:$U$135,2,false) this kind of values.
    By yogeshsharma1981 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2013, 04:08 PM
  5. vlookup? match? index? MULTIPLE criteria for vlookup search problem....
    By aborg88 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-11-2013, 09:56 AM
  6. Replies: 5
    Last Post: 07-29-2009, 07:53 AM
  7. [SOLVED] vlookup function-Can vlookup command find the data from the 5 sheets.
    By Rishab shah in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 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