+ Reply to Thread
Results 1 to 21 of 21

Range Names Breaking

Hybrid View

drchris Range Names Breaking 11-06-2009, 09:43 AM
DonkeyOte Re: Range Names Breaking 11-06-2009, 09:54 AM
Andy Pope Re: Range Names Breaking 11-06-2009, 09:56 AM
drchris Re: Range Names Breaking 11-06-2009, 09:59 AM
drchris Re: Range Names Breaking 11-06-2009, 10:04 AM
Andy Pope Re: Range Names Breaking 11-06-2009, 10:07 AM
romperstomper Re: Range Names Breaking 11-06-2009, 10:07 AM
drchris Re: Range Names Breaking 11-06-2009, 10:14 AM
Andy Pope Re: Range Names Breaking 11-06-2009, 10:23 AM
romperstomper Re: Range Names Breaking 11-06-2009, 10:23 AM
drchris Re: Range Names Breaking 11-06-2009, 10:32 AM
Andy Pope Re: Range Names Breaking 11-06-2009, 10:35 AM
romperstomper Re: Range Names Breaking 11-06-2009, 10:35 AM
drchris Re: Range Names Breaking 11-06-2009, 10:38 AM
DonkeyOte Re: Range Names Breaking 11-06-2009, 10:55 AM
Andy Pope Re: Range Names Breaking 11-06-2009, 10:59 AM
drchris Re: Range Names Breaking 11-06-2009, 11:01 AM
Andy Pope Re: Range Names Breaking 11-06-2009, 11:07 AM
drchris Re: Range Names Breaking 11-06-2009, 11:23 AM
DonkeyOte Re: Range Names Breaking 11-06-2009, 11:31 AM
romperstomper Re: Range Names Breaking 11-06-2009, 11:35 AM
  1. #1
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Range Names Breaking

    Guys,

    I have problem which has been puzzling me today at work and I would like someones help please.

    I have a sheet where you paste data in it, and by pressing a button sort_data it does a lot of sorting, filtering, deleting and so on. That works fine.

    Then, I wanted to delete data according to a list and followed Richards instructions on:
    http://www.excelforum.com/excel-prog...d-on-list.html

    So I am creating two range names:

    1. Data:
    =OFFSET('Outstanding Confirmations'!$A$1,0,0,COUNTA('Outstanding Confirmations'!$A:$A),28)

    2. Deletecriteria:
    =OFFSET('deletecriteria'!$A$1,0,0,COUNTA('deletecriteria'!$A:$A),1)


    However, following the sort_data method above, the first range becomes:

    1. Data:
    =OFFSET('Outstanding Confirmations'!#REF!,0,0,COUNTA('Outstanding Confirmations'!#REF!),28)

    Making it impossible for the macro code to delete the rows.

    Is there any way to fix it? For example I had though of defining the range name in the actual vba code just before the rows are deleted.

    Thanks
    DrChris

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Range Names Breaking

    If you're deleting either ROW 1 or COLUMN A then the linked cells in the Name are being removed hence #REF!

    Simplest perhaps is to try and revert to INDIRECT based approach for the name creation, eg:

    =OFFSET(INDIRECT("'Outstanding Confirmations'!A1"),0,0,COUNTA(INDIRECT("'Oustanding Confirmations'!A:A")),28)

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Range Names Breaking

    One way would be to move the data table down a few rows and adjust the OFFSET formula

    Data starts in row 4.

    =OFFSET(Sheet1!$A$1,3,0,COUNTA(Sheet1!$A:$A),4)
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    DonkeyOte

    Firstly thank you for your answer and very prompt reply.

    I've tried this and by using your piece of code now, it only selects the first row. (both before and after sorting the data), rather than the whole list as before.
    Last edited by drchris; 11-06-2009 at 10:05 AM.

  5. #5
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    Andy,

    Thank you for your reply mate.

    That could work, but its not very convenient as colleagues would use this new sheet by importing data from a trading platform into it; which does all the sorting.
    So this would mean that I have to somehow instruct them to paste in row4 now which (knowing them) would entail a disaster!

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Range Names Breaking

    Only has to be NOT row 1.

    Having users can cause you all sorts of problems

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Range Names Breaking

    Try using this: =INDEX('Outstanding Confirmations'!$A:$A,1):INDEX('Outstanding Confirmations'!$AB:$AB,COUNTA('Outstanding Confirmations'!$A:$A))
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    Romp:

    Thanks for your reply. I get the same problem after sorting

    =INDEX('Outstanding Confirmations'!#REF!,1):INDEX('Outstanding Confirmations'!#REF!,COUNTA('Outstanding Confirmations'!#REF!))

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Range Names Breaking

    drchris, I can only get the #REF with romp's suggestion if i delete columns A:AB.
    Sorting has no effect.

    Perhaps you should post an example workbook with any code you are using.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Range Names Breaking

    Which version of Excel? I find it odd that sorting would cause that with a whole column reference!

  11. #11
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    Andy,
    Agreed, I get the #REF as I am doing this in my sort_code data:

        
        Columns("A:A").Select
        Selection.Delete Shift:=xlToLeft
        Rows("1:1").Select
        Selection.Delete Shift:=xlUp
    Its Excel 2002 SP3.

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Range Names Breaking

    So you are deleting not sorting.

    And you are deleting an item that the formula refers to. So, as DO pointed out, deleting the range/row/column that is referenced will cause #REF

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Range Names Breaking

    Since you are using code anyway, why not create the name after you do the delete?

  14. #14
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    Romp:
    Ya that would be a good solution but I have no clue how to do that in vba!

    Andy:
    Indeed. I mentioned that in my initial post see above:
    '....and by pressing a button sort_data it does a lot of sorting, filtering, deleting and so on'.

    Very true what you said. What I was after really was a workaround

    Cheers
    Chris

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Range Names Breaking

    Andy:
    Indeed. I mentioned that in my initial post see above:
    '....and by pressing a button sort_data it does a lot of sorting, filtering, deleting and so on'.
    And on which basis I based my approach in post # 2 ?
    INDIRECT will not generate #REF errors if you delete the rows nor even the sheet in full assuming it's replaced like-for-like.

    You could still use INDEX if you were to reference the entire sheet and set column numbers appropriately but I believed INDIRECT to be the simpler approach and based on my own interpretation of things I've read regards how Names are evaluated I felt it whould not lead to any significant drawbacks over INDEX method
    (despite INDIRECT being a Volatile function in it's own right and INDEX not)

  16. #16
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Range Names Breaking

    Why use a named range, in this instance?

    Sub DeleteRows()
        
        With Sheet1
            With .Range("A1").CurrentRegion
                .AdvancedFilter action:=xlFilterInPlace, criteriarange:=Range("deletecriteria")
                .Offset(1, 0).Resize(.Rows.Count - 1, 4).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            End With
            .ShowAllData
        End With
        
    End Sub
    Macro recorder may help with adding/deleting a named range

  17. #17
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    Hello DO.

    Yes I did and I posted a comment on it above:

    With indirect, doesnt cause the #REF error which is a good start, but using that line of code you pasted only highlights the first row of my data, either before or after the sort_data function.

    I very much agree. I've read about Indirect myself after you mentioned it and it looks in theory a much simpler approach since it just converts the cell reference to text.

  18. #18
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Range Names Breaking

    row 1 only with indirect is due to a typo in sheet name

    =OFFSET(INDIRECT("'Outstanding Confirmations'!A1"),0,0,COUNTA(INDIRECT("'Outstanding Confirmations'!A:A")),28)

  19. #19
    Registered User
    Join Date
    10-12-2007
    Posts
    36

    Re: Range Names Breaking

    Much better now. Thank you for spotting that Andy - and DO for suggesting the INDIRECT command.

    It works like a treat now.

    Guys your help has been invaluable. I cant thank you enough.

    Regards from cold London - although I presume Essex and Suffolk are not that warm either

  20. #20
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Range Names Breaking

    Apologies for the typo - I should have checked (this is what happens when you do things on the fly!)

    I'm with both Andy & R though - given you're using VBA it would probably be best to resolve your names via that route.

    And yes - it's chilly in Suffolk - my boiler is presently drinking heating oil likes it's going out of fashion ... might be cheaper to just burn some five pound notes in the middle of the room

  21. #21
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Range Names Breaking

    Quote Originally Posted by DonkeyOte View Post
    my boiler is presently drinking heating oil likes it's going out of fashion ... might be cheaper to just burn some five pound notes in the middle of the room
    Sounds like my Aga!

+ 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