Consulting

Results 1 to 6 of 6

Thread: VBA creating relative references to table columns

  1. #1

    VBA creating relative references to table columns

    When I run the code below it enters the correct formula except that the column name in the match function needs to be a relative reference and it is entered as an absolute reference. If I manually enter the formula and drag it to other columns then it updates as expected. How can I make the column reference relative?


    With wsCurrent.ListObjects("tblActiveProjects").DataBodyRange.Columns("B:T")
            .Formula2R1C1 = _
            "=VLOOKUP([[Project Name]:[Project Name]]," & tblImport.Address(ReferenceStyle:=xlR1C1, External:=True) & ",MATCH(tblActiveProjects[[#Headers],[Project Version]]," & headerImport.Address(ReferenceStyle:=xlR1C1, External:=True) & ",0),FALSE)"
            .Value = .Value
        End With

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    Try

    .Address (False, True, xlR1C1, True)
    
    or
    
    .Address (ColumnAbsolute := False, ....

    https://docs.microsoft.com/en-us/off...6)%26rd%3Dtrue
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Thanks Paul for your response... I'm not sure I understand where I would insert the .Address property. I've tried a couple different things with no success. Where do I add this line of code?

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    Where do I add this line of code?
    Where ever you use .Address. It's not a separate line of code, but an additional parameter

    tblImport.Address (ColumnAbsolute := False, ReferenceStyle:=xlR1C1, External:=True)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Ok, I don't think that will work here. The specific line of code that is a problem does not use the .address property.

    Below is the code that would need to be modified. tblActiveProjects is the table the formula is entered into. tblImport is another table located in a separate workbook.

    MATCH(tblActiveProjects[[#Headers],[Project Version]]

    With wsCurrent.ListObjects("tblActiveProjects").DataBodyRange.Columns("B:T")
            .Formula2R1C1 = _
            "=VLOOKUP([[Project Name]:[Project Name]]," & tblImport.Address(ReferenceStyle:=xlR1C1, External:=True) & ",MATCH(tblActiveProjects[[#Headers],[Project Version]]," & headerImport.Address(ReferenceStyle:=xlR1C1, External:=True) & ",0),FALSE)"
            .Value = .Value
        End With

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    Sorry then

    Since I had nothing to test with, I could only do a desk check of the code and I concentrated on the .Address parts since that's where I know that relative/absolute addressing falls
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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