+ Reply to Thread
Results 1 to 3 of 3

Multiple to insert multiple vlookup formulas

  1. #1
    Registered User
    Join Date
    11-11-2013
    Location
    Johannesburg
    MS-Off Ver
    Excel 2010
    Posts
    9

    Multiple to insert multiple vlookup formulas

    Good day all,

    I am looking for a macro to allow me to insert multiple vlookups onto a spreadsheet which is utilised as a template. My template basically creates another sheet and transfers the data as well, thereafter clears the selected range from the template thereby also removing the formulas as well. I would like a macro that would reinsert these formulas. I tried to record a macro by physically inserting the formulas one by one but I get a run time error. The recorded macro is below


    PHP Code: 
    Option Explicit
    Sub Insert_Formulas
    ()
    '
    Insert_Formulas Macro
    '

    '
        
    ActiveCell.Offset(-12, -24).Range("A1").Select
        Selection
    .ClearContents
        ActiveCell
    .Offset(1, -1).Range("A1:C1").Select
        Selection
    .ClearContents
        ActiveCell
    .Offset(-351).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'C:\Users\Ridwan\Dropbox\Petrocam Finance (Group)\Repository\[PFI_Archive.xlsm]Summary'!R2C2:R1000C17,3),"""")"
        
    ActiveCell.Offset(-341).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'C:\Users\Ridwan\Dropbox\Petrocam Finance (Group)\Repository\[PFI_Archive.xlsm]Summary'!R2C2:R1000C17,4),"""")"
        
    ActiveCell.Offset(-331).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'C:\Users\Ridwan\Dropbox\Operations (Group)\petrocam operations (Group)\Work in Progress\[Operation Workbook Summary.xlsx]Operation Workbook Summary'!R2C2:R1000C12,7,0),0)"
        
    ActiveCell.Offset(-3226).Range("A1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "IFERROR(VLOOKUP($B$2,'C:\Users\Ridwan\Dropbox\Operations (Group)\petrocam operations (Group)\Work in Progress\Repository\[Operation Workbook Summary.xlsx]Operation Workbook Summary'!$B$2:$L$1000,4,0),0)"
        
    ActiveCell.Offset(-321).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,4,0),0)"
        
    ActiveCell.Offset(-311).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,5,0),0)"
        
    ActiveCell.Offset(-301).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,6,0),0)"
        
    ActiveCell.Offset(-291).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,8,0),0)"
        
    ActiveCell.Offset(-271).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,9,0),0)"
        
    ActiveCell.Offset(-261).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,10,0),0)"
        
    ActiveCell.Offset(-251).Range("A1:C1").Select
        ActiveCell
    .FormulaR1C1 _
            
    "=IFERROR(VLOOKUP(R2C2,'Operation Workbook Summary.xlsx'!R2C2:R1000C12,11,0),0)"
        
    ActiveCell.Offset(-231).Range("A1:C1").Select
        ActiveCell
    .Offset(212).Range("A1").Select
        Selection
    .ClearContents
        ActiveCell
    .Offset(-1, -2).Range("A1").Select
        Selection
    .ClearContents
            ActiveWorkbook
    .Save
    End Sub 
    Your help will be most appreciated.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Multiple to insert multiple vlookup formulas

    Hi,

    The workbook would be more useful, particularly since we don't know what the active cell was at the time you recorded the macro.

    In any case, ignore the macro you have. Recorded macros are occosionally a useful starting point, but they always need editing and modifying to make them truly workable.

    Tell us exactly what you are trying to do in a narrative form. It appears that you are wanting to enter one or more VLOOKUP formula in several cells. Tell us what the formulae are attempting to do and where you expect them to be placed. And if this is not always the same place, what rules should be used for placing the formulae
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-11-2013
    Location
    Johannesburg
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Multiple to insert multiple vlookup formulas

    Hi

    Please find attached,basically it the sheet has look ups to another summary sheet (Pro Forma Invoice Summary) from which it extracts the information and compares this to the LC data inputted into Column C. Prior I had two macros, one to move to copy data to another sheet and another to clear cells. Formulas are also included in the cells as comments and want these to be automatically inserted.

    I have changed the macro since, thou I am having an error on the spreadsheet and made a note in the document. The idea now is that the sheet is duplicated then moved to the archive workbook behind the summary sheet and stored there, a PDF is created, named and stored in separate location and the template files is then closed.

    Your advise on the volookups message will be most appreciated. Placing of formulas will not change.
    Attached Files Attached Files
    Last edited by Rid1; 01-16-2014 at 03:47 PM. Reason: correct request

+ 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 to insert rows in multiple sheets and copy formulas
    By syt0x in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2013, 11:06 AM
  2. [SOLVED] Insert Multiple Rows and Copy Formulas Only
    By hallelujah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2013, 07:20 PM
  3. [SOLVED] Insert Row on Multiple Sheets - Copy Formulas
    By mattmar09xu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-22-2012, 07:19 AM
  4. Vlookup Multiple Values if more than 1 insert new row
    By natural in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2010, 03:59 PM
  5. insert Rows with Formulas in Place on Multiple Sheets?
    By Michael Link in forum Excel General
    Replies: 5
    Last Post: 03-09-2006, 10:00 AM

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