+ Reply to Thread
Results 1 to 2 of 2

Expand Single Row Range References

  1. #1
    Registered User
    Join Date
    10-12-2012
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Expand Single Row Range References

    I couldn't find a solution to my problem anywhere online, so I thought I'd post up the one I came up with.

    My problem essentially stems from accidentally deleting too many rows. I know that many frown upon deleting rows and recommend clearing them instead, but for a variety of reasons, in my particular case, I needed to delete them. Incidentally, this is done programmatically on a number of different sheets.

    The sheets in question have a variety of sometimes rather complex formulas in the first several rows, which compute on data in lower rows. By inserting and deleting rows, the references are automatically expanded and contracted. Unfortunately at one point I "reset" the data, and deleted all of the data rows but the very first one, and all of those references now pointed to a single row. E.g. I went from something like A1:=SUM(A2:A25), to A1:=SUM(A2:A2). Now there was no way to get those single row references to expand. Unfortunately I didn't notice this as an issue for quite some time, and in the meantime I'd made quite a few changes that precluded the option of copying the formulas from an older backup of the file.

    I wrote the following VBA to correct the problem. It uses regular expressions to find any ranges from a single cell to the same cell. It finds and preserves any combination of absolute and relative references. As written it expands the range by one row, which could be changed fairly easily to a larger static number, or something dynamic. This could also be modified to take said range and move the second reference over by a column instead. I think this would be easiest by switching to R1C1 notation and rewriting the regular expressions. Which, I should point out, this is currently for A1 style references only!

    Please Login or Register  to view this content.
    It's kind of sloppy, with little in the way of error checking, but it was meant to be a tailor to suit solution. Hopefully it may help someone in the future.
    Last edited by Paul; 10-15-2012 at 12:31 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Expand Single Row Range References

    Thank you for posting this.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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