+ Reply to Thread
Results 1 to 5 of 5

Moving a cell on a worksheet does not move reference in VBA

  1. #1
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Moving a cell on a worksheet does not move reference in VBA

    Is there a way that I can move rows or columns of data in a worksheet around and have the cell's location reference in VBA change too? Now, if I move a cell that I have VBA code acting upon, I need to remember to go back and change all the VBA code for each cell affected.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,767

    Re: Moving a cell on a worksheet does not move reference in VBA

    Why don't you use a Named Range reference in your VBA code. So that the named range will get auto adjusted if there is any replacement in position.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Moving a cell on a worksheet does not move reference in VBA

    Depends very much on your workbook layout, what it does and what you're moving.

    For example, if you have a single cell/range that you're referring to in the code then you could name that cell/range and refer to the name rather than the cell/range reference. That way if you add new rows/columns and the cell/range position moves the code will still find it.
    But if you have hundreds of cells or ranges then you can see how this could be problematic.

    BSB


    EDIT: Sixthsense beat me to it

  4. #4
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: Moving a cell on a worksheet does not move reference in VBA

    Thank you both...I do have hundreds of cell references...many could be named ranges, and for those I could make things simpler using names but I'm still left with a lot that are not so easily managed without creating dozens of different names. I was hoping for something that didn't require doing that.

  5. #5
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: Moving a cell on a worksheet does not move reference in VBA

    Using named ranges was a great solution and has saved me a few hundred lines of code changes. I still have some updating to do in some cases, but this has saved tons of work....thanks!

+ 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. moving a cell reference down one row automatically
    By tmillerbkpr in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-17-2014, 04:03 PM
  2. Replies: 0
    Last Post: 01-02-2014, 02:03 PM
  3. Reference a moving cell in another table
    By Carson Dyle in forum Excel General
    Replies: 4
    Last Post: 05-31-2013, 01:29 AM
  4. Need to move data that matches criteria in cell and move to new worksheet
    By panagle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2013, 09:23 AM
  5. Moving left of a cell reference
    By jagbabbra in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-13-2006, 09:15 AM
  6. Moving left of a cell reference
    By jagbabbra in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-13-2006, 09:01 AM
  7. [SOLVED] Moving Cell Reference after Sorting
    By [email protected] in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 03-11-2006, 07:15 PM

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