+ Reply to Thread
Results 1 to 2 of 2

Insert Column after Column X, then use Vlookup on multiple workbooks

  1. #1
    Registered User
    Join Date
    11-29-2017
    Location
    Bristol, England
    MS-Off Ver
    2013
    Posts
    1

    Insert Column after Column X, then use Vlookup on multiple workbooks

    Long time Excel user, but new to Macros.

    I’m trying to copy a set of date from Sheet1 to Sheet2, insert a column in Sheet2 after a column titled “Registered Number” and then in the new column in Sheet2 run a vlookup through multiple workbooks for the value in the Registered Number column.

    The Registered Number column won’t always be in the same place, so I’ve managed to put together the code to find the column and insert a new column after this column and insert “Match” in R1 of that column.

    This part works fine

    Private Sub CommandButton1_Click()
    Sheets("Sheet1").Range("A1").CurrentRegion.Copy Destination:=Sheets("Sheet2").Range("A1")
    Dim SearchText As String
    Dim GCell As Range
    SearchText = "Registered Number"
    Set GCell = Worksheets("Sheet2").Cells.Find(SearchText).Offset(0, 1)
    GCell.EntireColumn.Insert
    Worksheets("Sheet2").Cells.Find(SearchText).Offset(, 1).Value = "Match"
    End Sub


    So for example in Sheet2 we should now have Columns A=Number, B = Description, C = Registered Number, D = Match and E = Spend

    I want to insert a vlookup in whichever column Match is in (for this example D) which will match the value in Registered Number (Always the column before: for this one C) to one of 10 workbooks (There was too much data for a single table and my PC struggled with all the data in 1 workbook and 10 sheets).

    The Registered Numbers start 00, 01, 02 etc. to 10 and the Workbooks are called “RN 000.xlsx”, “RN 010.xlsx” etc. etc. Also the Registered Numbers are Numbers stored as Text (To allow for the starting 0).



    If possible I would like code to do the following;
    In the Match (D) Column, run the vlookup depending on the first 2 digits of the Registered Number and continue to run this for each row containing a value in the Registered Number Column (C). The number of rows will also change so this will need to keep going until there is a "" value in Column C.

    Thanks for your help

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: Insert Column after Column X, then use Vlookup on multiple workbooks

    You can solve some of your problem by organizing your data into an Excel Table. Excel tables do thing by Column Header name and not by column position. Also Excel Tables automatically copy down formulas, so if you add the formula to a single cell in a newly-created column, it will populate automatically to all rows in that column. That's about as far as I can take the advice without actually seeing a workbook.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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] Insert vlookup formula into next empty cell in column B
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2016, 05:55 AM
  2. [SOLVED] VLOOKUP between workbooks, don't return results matching a 2nd column criteria?
    By Tunesmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2014, 11:58 AM
  3. [SOLVED] Macro to Insert column and include a VLOOKUP array for entire column
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-29-2014, 06:28 PM
  4. [SOLVED] Insert Column with vLookup formula
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2013, 03:03 AM
  5. Insert column and fill column upto where data is in previous column
    By aka189 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2012, 06:07 AM
  6. [SOLVED] VBA to Open all WorkBooks in A folder and Insert a Hidden Column
    By jo15765 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-20-2012, 01:02 PM
  7. How to insert "column A" into multiple workbooks automatically
    By theflight in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2009, 12:01 PM

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