+ Reply to Thread
Results 1 to 13 of 13

Copy Vlookup Formula to alternate columns

  1. #1
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question Copy Vlookup Formula to alternate columns

    I have a very large spreadsheet with over 400 columns of data, I wish to copy a Vlookup formula to each alternate column, this is so I can validate data between two different spreadsheets.
    The number of rows in the spreadsheets differ, but I also need to be able to copy and paste the formula into each row of each alternate column as well. I have been looking at various methods to do this but cannot find one that incorporates all the functions necessary to complete these tasks.
    I am looking for a macro which could be edited to achieve this goal fr each spreadsheet. or one that can identify the total number of rows present, this could look in Column A, and for the last cell in row 1, which contains my column header data + 1 being the last column I would need to paste the formula.
    Also, when pasting the formula to the alternate columns, I need to amend the Col_Index_Num in the Vlookup formula to increment by one for each entry, so it refers to the correct column in the lookup spreadsheet.

    The one saving grace is that there are only between 90 and 500 rows of data in the final spreadsheets, the width is the main problem, I do not fancy having to insert all these by hand.
    Any help would be appreciated.
    Last edited by Brilar; 08-09-2011 at 04:37 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Vlookup Formula to alternate columns

    If you showed us the formula you would paste into A500 and then the formula you would paste into C500, that may be enough for use to recommend ONE formula you can place in A500 and just COPY across the whole row and it still do what you want.

    What are those two formulas?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Vlookup Formula to alternate columns

    Quote Originally Posted by JBeaucaire View Post
    If you showed us the formula you would paste into A500 and then the formula you would paste into C500, that may be enough for use to recommend ONE formula you can place in A500 and just COPY across the whole row and it still do what you want.

    What are those two formulas?
    The formulas start in cell C2 and goes through to OY2, this first formula is - =VLOOKUP(A$2,'External survey data-Rev 010711.csv'!$A$2832:$GZ$2887,2,FALSE) this formula then needs to be copied to each alternate column until the end of data headers +1, cell OY2.
    In each alternate column where this formula appears it then needs to be copied down to the end of data in each row. Column A1 has data in every row, so this should be used to count how many rows down to copy formula.

    In the formula, the 2 to the left of FALSE needs to be incremented by 1 on each copy to alternate columns to keep the lookup data in tact, to match that of the original data in the column to the left of the lookup data. This is so I can then validate and compare the data.

    I already have the code to add in the alternate blank columns, I just need the code to save me one hell of a lot of work in filling these columns with data.
    Code used to add alternate columns:
    Sub insert_column_every_other()
    For colx = 2 To 420 Step 2
    Columns(colx).Insert Shift:=xlToRight
    Next
    End Sub

    Your help is appreciated.

    I hope this makes sense.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Vlookup Formula to alternate columns

    So, the first formula you wanted in cell ______ was __________________________?

    The second formula you wanted in cell ______ was __________________________?


    We can work out how far down to copy things later, just working on creating a single formula for you. Is there anything in the columns in between? No chance we can see a smaller sample showing example data and example formulas?

  5. #5
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Vlookup Formula to alternate columns

    I have attached two files the first listed is the one I wish to compare and have added the blank columns in the second tab to which the vlookup data is to go.
    The second file is the original existing data which the vlookup is getting the data from.
    In the second tab of the first file I have created the Vlookup formula in cells A3 and A5, note the Col_index_num is incremented by one in the Vlookup formula.
    These need to go the whole width of the spreadsheet in the blank columns, also in each row to the end. I can then compare the collected data against our original data.

    Hope this helps.
    Brian

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Vlookup Formula to alternate columns

    I see a VLOOKUP in C2 and E2... is that what you meant?

    You can use the COLUMN() function and do some fun math until you get the result to equal the same as some incrementing number you want. For instance...

    =COLUMN() placed in cell C2 would result in 3... because column C is column 3. So, how do we create a formula with COLUMN() that will convert 3 to 2 when placed in column C, 5 to 3 when placed in column E, 7 to 4 when placed in column G, etc.

    =(COLUMN()-1)/2+1 ....does it.

    So in your original C2 Vlookup formula, we replaced the hardcoded 2 in the third parameter with that formula, and now your VLOOKUP will adjust itself as you copy from column to column.

    =VLOOKUP($A2,'N:\Marches\[External survey data-Rev 010711-Sample.xlsm]Sheet1'!$A$2:$GZ$35,(COLUMN()-1)/2+1,FALSE)

  7. #7
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Vlookup Formula to alternate columns

    Thanks, that bit works and resolves one of my issues.
    Having a formula which does what I now want, it now has to go into all the blank columns to the right and then in each blank column copied down to the last row of data. There can be over 300 columns to copy to, can this be automated?
    A macro to do this would be fine. I can place the Vlookup formula in cell C2 then the macro would take over and fill the appropriate columns and rows. Any help appreciated. Brian

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Vlookup Formula to alternate columns

    Which column is used to determine how far down to copy?

  9. #9
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Vlookup Formula to alternate columns

    It is column A in all cases.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Vlookup Formula to alternate columns

    Hmm, your original question made it seem like the blank columns would be every other column... that you would want the formula placed in column B, then D, then F, etc... but now you say "in blank columns" and you have blank columns all over the place.

    Can you provide more exact instructions as to where the formulas go?

  11. #11
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Vlookup Formula to alternate columns

    Looking at Row 1, you will notice that every other column does not have a heading, these I am calling my Blank columns, therefore the formula needs to be placed in each of these columns (alternately) and in each row in each of these columns. The heading for each column in each spreadsheet are the same to begin with, I have added in these blank columns in the Rand data spreadsheet so that I can compare the new data with the old side by side. Hence the need to copy the formula to each alternate column, the blank header ones. Yes there will be columns were there is no data and they are blank also, but we are looking for the ones were there is no header in row 1.

    Hope this explains a bit clearer.

    Regards

    Brian

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Vlookup Formula to alternate columns

    So, this should do it:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-02-2011
    Location
    Hemel Hempstead, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Vlookup Formula to alternate columns

    The code works and does the job required . Many thanks for your help.
    Last edited by Brilar; 08-09-2011 at 04:35 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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