+ Reply to Thread
Results 1 to 2 of 2

VBA Formula referencing another workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    21

    VBA Formula referencing another workbook

    I am trying to insert a formula that looks up cells in a different workbook. Can someone help me with my code below? I want the formula to be dynamic so as I do this next month and the file changes, I don't have to change the entire code with every line that has this formula, as a similar one will be inputted in multiple locations of my code.

    Thanks!

    Application.Workbooks.Open("C:\Documents\Book1.xlsx")
    wbkDataLoad = ActiveWorkbook
    
    Thisworkbook.Sheets("Sheet1").Range("A2").Activate
    ActiveCell.Formula = "=sumif(" & wbkDataLoad & "Sheet1'!$R$2:$R$100,$B2," & wbkDataLoad & "Sheet1'!$Z$2:$Z$100)"

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Formula referencing another workbook

    perhaps
    Application.Workbooks.Open("C:\Documents\Book1.xlsx")
    wbkDataLoad = "'[" & ActiveWorkbook.name & "]"
    
    Thisworkbook.Sheets("Sheet1").Range("A2").Formula = "=sumif(" & wbkDataLoad & "Sheet1'!$R$2:$R$100,$B2," & wbkDataLoad & "Sheet1'!$Z$2:$Z$100)"
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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