Results 1 to 6 of 6

Thread: Maintaining Column References

  1. #1

    Maintaining Column References



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I have attached a macro enabeled worksheet that will create a Word document based on the data entered into a row.

    If a user inserts a column, the offsets get messed up, and so too will the word document.

    How can I dynamically maintain the column references if this occurs.

  2. #2
    Sorry, Here is the attachment.
    Attached Files Attached Files

  3. #3
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,294
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    If I was concerned about my users mucking with the sheet, what I would do is:
    • Name the header ranges. i.e. I defined a range named "rngPA" on cell A1
    • Adjust your code to pick up intersects


    Try defining that name first. Then make sure you have the Immediate window showing and run this code:
    Code:
    irow = ActiveCell.Row
    Debug.Print Intersect(rows(iRow).Entirerow,Range("rngPA").EntireColumn).Address
    Debug.Print Intersect(rows(iRow).Entirerow,Range("rngPA").EntireColumn).Value
    I think you'll get the idea.
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  4. #4
    Thanks Ken, worked like a charm!

    Updated file attached.
    Attached Files Attached Files

  5. #5
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,294
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Excellent! So this one is sorted, yes?
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  6. #6
    Yes, Thanks, much appreciated!

Posting Permissions

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