LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Macro Adjust Based on Dataset?

if you want to manually select your data each time, before you run the
macro, you could change the macro to this:

Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:= _
Range("B2"), Order2:=xlAscending, Header:=xlGuess,
OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal


make sure you remove ---Range("A1").Select--- in that first row, or
that will kill your selection each time, making your selection Range
("A1") only.
hope that helps!
:)
susan



On Nov 18, 11:19*am, Jcraig713
wrote:
Good morning all.

BACKGROUND: *
I have a macro recorded to format data in my spreadsheet to a report when
printed (adjust column width, page setup, bold text, sort data excluding
headers etc.). *In the portion of that macro provided below (for sorting the
data), the range to sort looks up the range A:1 to I1087 as when I originally
recorded the macro, that was the size of my 'test' dataset. *The spreadsheet
will be used to accomodate many different datasets; smaller or larger numbers
of records to sort. *The result as is will be that if I have a dataset that
goes through row K1087 for example, after the macro is run, the records
through I1087 are sorted leaving the rest unsorted. *

QUESTION:
Is there a way, through coding or otherwise, to write something in the
recorded macro that will adjust the sort range to whatever length of dataset
is being worked with without having to manually change the macro everytime I
run the macro for the accompanying dataset?

Sample of Macro Sorting Code form my spreadsheet:

Range("A1").Select
* * Range("A1:I1087").Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:= _
* * * * Range("B2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
* * * * MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
* * * * DataOption2:=xlSortNormal

Thanks in advance for your time.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I autodelete rows in a macro on a variable dataset? bimpnottin_noregard Excel Discussion (Misc queries) 6 January 29th 09 06:19 PM
Macro Adjust Based on Dataset? Jcraig713 Excel Programming 1 November 18th 08 04:47 PM
Select and adjust a value based on a total Allison Excel Worksheet Functions 0 August 16th 06 11:21 PM
assign dataset to matching dataset Michael Dirksen Excel Programming 0 June 16th 06 04:34 PM
Converting A Quarterly Dataset to Weekly Dataset Dan Thompson Excel Programming 5 November 25th 05 09:27 PM


All times are GMT +1. The time now is 07:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"