Consulting

Results 1 to 4 of 4

Thread: Change workbook reference to variable

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Change workbook reference to variable

    I am trying to change this part [BusinessReportingReference.xlsm] in the following code to the variable that I use wbRef


    [VBA]rngAddto.FormulaR1C1 = _
    "=VLOOKUP(RC[" & intColumnDiff & "],'[BusinessReportingReference.xlsm]Products'!C1:C2,2,FALSE)"[/VBA]

    I can't figure it out

  2. #2
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    sould be something like this


    [VBA]rngAddto.FormulaR1C1 = _
    "=VLOOKUP(RC[" & intColumnDiff & "],'[" & wbRef.Name & "]Products'!C1:C2,2,FALSE)"[/VBA]

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I am in the process of testing this code and with both my old version of code and the new version I am getting the same error application-defined or object-defined error. I never recieved this error for this code under Excel 2003 but under 2007 I am. Here is the full code:

    Old:

    [VBA]Sub comAddCust(ByVal rngAddto As Range, ByVal intColumnDiff As Integer)

    rngAddto.FormulaR1C1 = _
    "=VLOOKUP(RC[" & intColumnDiff & "],'[BusinessReportingReference.xlsx]Cust'!C1:C2,2,FALSE)"
    rngAddto.Value = rngAddto.Value
    End Sub[/VBA]

    New:

    [VBA]Sub comAddCust(ByVal rngAddto As Range, ByVal intColumnDiff As Integer)

    rngAddto.FormulaR1C1 = _
    "=VLOOKUP(RC[" & intColumnDiff & "],'[" & wbRef.Name & "]Cust'!C1:C2,2,FALSE)"
    rngAddto.Value = rngAddto.Value
    End Sub[/VBA]

  4. #4
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    For anybody that has this problem I fixed it. The problem is the worksheet that I was performing the vlookup on was the old format and the lookup sheet was the new format. This caused it to crash.

    Thank you all for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •