+ Reply to Thread
Results 1 to 10 of 10

Sorting with Cell References

  1. #1
    Registered User
    Join Date
    02-01-2016
    Location
    New York, US
    MS-Off Ver
    Mac 2011
    Posts
    5

    Sorting with Cell References

    Hi!

    I created the attached workbook to serve as a template for encoding responses to a survey. It will be distributed to multiple users. The workbook contains six spreadsheets that refer to each other using a simple formula (=Stratification!N5). Because of this, I cannot seem to be able to sort or delete rows as the formula moves with the row instead of remaining static. (Information from the spreadsheet entitled Phil PEN is fed into the spreadsheet entitled Stratification. There is a formula in column N of the the Stratification tab, the response to which is fed back into column J of Phil PEN tab. If I wanted to sort the data in the Phil PEN tab alphabetically the formula in column J moves with the row, which no longer references the correct data) Is there a way to work around this?

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Sorting with Cell References

    Quote Originally Posted by tangerinezebra View Post
    If I wanted to sort the data in the Phil PEN tab alphabetically the formula in column J moves with the row, which no longer references the correct data)
    I'm not sure I follow what you're asking. If you exclude column J from the sort (deselect column J before sorting), wouldn't that solve your problem.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    02-01-2016
    Location
    New York, US
    MS-Off Ver
    Mac 2011
    Posts
    5

    Re: Sorting with Cell References

    How would I deselect the column? I have information in columns A to CD. Columns BR to CD also references information in other sheets. Thank you!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Sorting with Cell References

    My bad. Excel won't sort multiple areas.

    One suggestion could be to restore the original formulas after sorting.

    Example:
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Sorting with Cell References

    Do you mean after sorting also in Column J Row 5 formula should be
    ==Stratification!N5
    and further.
    If it so , in J5
    =INDIRECT("Stratification!N"&ROW())
    then drag down.
    Even if you sort the data including J column, Data in column J will not change.
    Last edited by kvsrinivasamurthy; 02-01-2016 at 11:23 AM.

  6. #6
    Registered User
    Join Date
    02-01-2016
    Location
    New York, US
    MS-Off Ver
    Mac 2011
    Posts
    5

    Re: Sorting with Cell References

    There are 16 columns where the formulas would have to be restored. F, H, J, and BR to CD. I sorted and restored the formulas manually as I don't know how to manipulate the code AlphaFrog posted and it seemed to work. The recorded macro is below. There are instances where the formula is overridden though, which is lost when I manually restored the formula by dragging the first cell down.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-01-2016
    Location
    New York, US
    MS-Off Ver
    Mac 2011
    Posts
    5

    Re: Sorting with Cell References

    Quote Originally Posted by kvsrinivasamurthy View Post
    Do you mean after sorting also in Column J Row 5 formula should be
    ==Stratification!N5
    and further.
    If it so , in J5
    =INDIRECT("Stratification!N"&ROW())
    then drag down.
    Even if you sort the data including J column, Data in column J will not change.
    That is what I meant and the formula you provided seemed to have worked! How would I change the below formula to include the indirect function as well? When I sorted, the 'Hypertension Confirmation'! portion continued to refer to row 10 when it should refer to row 5. Thank you!!

    =IF('Hypertension Confirmation'!AL10="Confirm","Suspected",IF(AND('Hypertension Confirmation'!AL10>=140,AQ5="YES"),"Confirmed Yes",IF(AND('Hypertension Confirmation'!AL10<140,AQ5="YES"),"Confirmed No",IF(AQ5="Yes","Suspected",IF(AQ5="No","No","")))))

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Sorting with Cell References

    Quote Originally Posted by tangerinezebra View Post
    There are instances where the formula is overridden though, which is lost when I manually restored the formula by dragging the first cell down.
    I didn't follow what you meant by that.

    Here's your code cleaned up a bit
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Sorting with Cell References

    Formula for F5, then drag down
    Please Login or Register  to view this content.
    Since the cells are validated , it may not be possible to edit formula.
    So, Remove the data validation. Apply the formula in the column. Then redo the validation.

  10. #10
    Registered User
    Join Date
    02-01-2016
    Location
    New York, US
    MS-Off Ver
    Mac 2011
    Posts
    5

    Re: Sorting with Cell References

    Thank you, AlphaFrog and kvsrinivasamurthy! I would like to use the INDIRECT function instead of a macro now so users can sort as they please. I have updated the attached with INDIRECT functions in columns F H J BR-CD. Sample data is included as well. However, when I sort,the data is scrambled. What could be the problem?

    The formulas are:

    F
    Please Login or Register  to view this content.
    H
    Please Login or Register  to view this content.
    J
    Please Login or Register  to view this content.
    BR
    Please Login or Register  to view this content.
    Thank you
    Attached Files Attached Files
    Last edited by tangerinezebra; 02-04-2016 at 11:45 AM.

+ 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. Sorting Table with Cell References
    By Statto in forum Excel General
    Replies: 5
    Last Post: 12-23-2014, 12:32 PM
  2. Sorting messes up cell references
    By Alpha Hunter in forum Excel General
    Replies: 2
    Last Post: 12-28-2010, 04:15 PM
  3. Replies: 3
    Last Post: 12-22-2010, 01:52 PM
  4. List sorting problem with external cell references
    By bobschwenkler in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 11-07-2008, 03:39 PM
  5. Sorting Changes Cell References
    By Camp2 in forum Excel General
    Replies: 2
    Last Post: 06-20-2008, 03:41 PM
  6. Replies: 1
    Last Post: 05-17-2008, 09:30 AM
  7. cell references lost after sorting
    By gert.everaert in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-17-2007, 02:13 AM

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