ExcelTip.com
Account Icon Account Icon Account Icon
ExcelTip.com

Go Back   Excel Help Forum > Usenet Groups > Excel 2007 Help

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-12-2008, 07:39 PM
bungaree bungaree is offline
Registered User
 
Join Date: 26 Dec 2006
Posts: 27
bungaree is on a distinguished road
Excel 2007 - Named range disappears in sort macro

I have several named ranges which are sorted individually. These ranges change, ie rows are added and deleted, hence the need for named ranges. Have been using this extensively in 2003 without any issue.

Now I've recorded a macro in 2007 to sort ranges, however within the actual macro, though it starts with Goto Reference:="dataA" (dataA = named range), the actual sort refers to columns & rows, ie B4:F70.

The range in the example above has grown to B4:B95, but is only being sorted up to row 70 as per the macro.

What can I do to keep the named range as the sort range within the macro?

Bungaree
Reply With Quote
  #2  
Old 07-12-2008, 09:14 PM
shg's Avatar
shg shg is online now
Forum Moderator
 
Join Date: 21 Jun 2007
Location: Dallas, Texas
Posts: 5,791
shg will become famous soon enough shg will become famous soon enough
Post the code?
Reply With Quote
  #3  
Old 07-12-2008, 09:50 PM
bungaree bungaree is offline
Registered User
 
Join Date: 26 Dec 2006
Posts: 27
bungaree is on a distinguished road
SHG,

I made the earlier one up, as the situation of several ranges is actually at work and I'm at home.

I discovered the 2007 problem in the macro below. I must have recorded it when there were 240 records and it was only sorting 240 rows though I had inserted about 50 more - I've solved it for this particular worksheet by making the range far larger than I'll ever need - a quick (ugly) fix for this one.

I do have other situations where the range needs to be flexible and would like to know why 2007 is causing probs with this.

Thanks in anticipation!
Bungaree
Code:
    Application.Goto Reference:="sort_stocklist"
    ActiveWorkbook.Worksheets("Prospects").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Prospects").Sort.SortFields.Add Key:=Range( _
        "i4:i2473"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("Prospects").Sort.SortFields.Add Key:=Range( _
        "a4:a2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Prospects").Sort
        .SetRange Range("A3:N2000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
End Sub

Last edited by royUK; 07-13-2008 at 04:15 AM.
Reply With Quote
  #4  
Old 07-13-2008, 04:13 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Lincolnshire,UK
Posts: 6,552
royUK will become famous soon enough royUK will become famous soon enough
bungaree

You need to read the Forum Rules & use Code Tags when posting code. I will add them this time, but next ime you my find your post closed.
__________________
Hope that helps.

RoyUK
--------
For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Where to copy the code to

Code Tags: Make your code easier for us to read
Reply With Quote
Reply

Bookmarks

New topics in Excel 2007 Help


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -4. The time now is 11:55 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0