PC Review


Reply
Thread Tools Rate Thread

Continue running macro until last line of data.

 
 
Steve
Guest
Posts: n/a
 
      24th Nov 2008
Using Excel 2003 I am attempting to create a macro where I can copy a set of
numbers, transpose them, sort them and copy/transpose them back to their
original location.

I have the macro working but I do not know how to have the application
continue the function until it has reached the end of my data set. I
currently have the macro running ten lines of data and then it stops.

(Example)
Range("C1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("X1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True
Columns("X:X").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("X1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("X1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True
Range("X1").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents

I have this code down to C10 but unfortunately, I have thousands of lines of
data so I need to enter code that keeps the macro running until it has
reached the end of my data set. The total number of lines varies from
hundreds to thousands.

I am sure there is a simple answer but I am having trouble figuring it out.
Any help would be greatly appreciated.

Steve

 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      24th Nov 2008
Since Excel 2003 supports sorting column-wise you can skip the copy/paste

'****************************************************
Sub Tester()
Dim rng As Range

Set rng = ActiveSheet.Range("C1")
Do While rng.Value <> ""

With ActiveSheet.Range(rng, rng.End(xlToRight))
.Sort Key1:=rng, Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Set rng = rng.Offset(1, 0)
Loop

End Sub
'****************************************************

Tim

"Steve" <(E-Mail Removed)> wrote in message
news:A3C0C236-DF7A-42BA-AC76-(E-Mail Removed)...
> Using Excel 2003 I am attempting to create a macro where I can copy a set
> of
> numbers, transpose them, sort them and copy/transpose them back to their
> original location.
>
> I have the macro working but I do not know how to have the application
> continue the function until it has reached the end of my data set. I
> currently have the macro running ten lines of data and then it stops.
>
> (Example)
> Range("C1").Select
> Range(Selection, Selection.End(xlToRight)).Select
> Selection.Copy
> Range("X1").Select
> Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> SkipBlanks:= _
> False, Transpose:=True
> Columns("X:X").Select
> Application.CutCopyMode = False
> Selection.Sort Key1:=Range("X1"), Order1:=xlAscending, Header:=xlGuess,
> _
> OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
> DataOption1:=xlSortNormal
> Range("X1").Select
> Range(Selection, Selection.End(xlDown)).Select
> Selection.Copy
> Range("C1").Select
> Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> SkipBlanks:= _
> False, Transpose:=True
> Range("X1").Select
> Range(Selection, Selection.End(xlDown)).Select
> Application.CutCopyMode = False
> Selection.ClearContents
>
> I have this code down to C10 but unfortunately, I have thousands of lines
> of
> data so I need to enter code that keeps the macro running until it has
> reached the end of my data set. The total number of lines varies from
> hundreds to thousands.
>
> I am sure there is a simple answer but I am having trouble figuring it
> out.
> Any help would be greatly appreciated.
>
> Steve
>



 
Reply With Quote
 
RadarEye
Guest
Posts: n/a
 
      24th Nov 2008
Hi,

As an alternative for
Do While rng.Value <> ""
you canuse
Do While Not IsEmpty(rng)

hth,
Wouter
 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      2nd Dec 2008
Tim,

Thanks for the help. It worked perfectly. I knew there had to be an easy
way to get it done.

Steve


"Tim Williams" wrote:

> Since Excel 2003 supports sorting column-wise you can skip the copy/paste
>
> '****************************************************
> Sub Tester()
> Dim rng As Range
>
> Set rng = ActiveSheet.Range("C1")
> Do While rng.Value <> ""
>
> With ActiveSheet.Range(rng, rng.End(xlToRight))
> .Sort Key1:=rng, Order1:=xlAscending, Header:=xlNo, _
> OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
> DataOption1:=xlSortNormal
> End With
> Set rng = rng.Offset(1, 0)
> Loop
>
> End Sub
> '****************************************************
>
> Tim
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:A3C0C236-DF7A-42BA-AC76-(E-Mail Removed)...
> > Using Excel 2003 I am attempting to create a macro where I can copy a set
> > of
> > numbers, transpose them, sort them and copy/transpose them back to their
> > original location.
> >
> > I have the macro working but I do not know how to have the application
> > continue the function until it has reached the end of my data set. I
> > currently have the macro running ten lines of data and then it stops.
> >
> > (Example)
> > Range("C1").Select
> > Range(Selection, Selection.End(xlToRight)).Select
> > Selection.Copy
> > Range("X1").Select
> > Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> > SkipBlanks:= _
> > False, Transpose:=True
> > Columns("X:X").Select
> > Application.CutCopyMode = False
> > Selection.Sort Key1:=Range("X1"), Order1:=xlAscending, Header:=xlGuess,
> > _
> > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
> > DataOption1:=xlSortNormal
> > Range("X1").Select
> > Range(Selection, Selection.End(xlDown)).Select
> > Selection.Copy
> > Range("C1").Select
> > Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> > SkipBlanks:= _
> > False, Transpose:=True
> > Range("X1").Select
> > Range(Selection, Selection.End(xlDown)).Select
> > Application.CutCopyMode = False
> > Selection.ClearContents
> >
> > I have this code down to C10 but unfortunately, I have thousands of lines
> > of
> > data so I need to enter code that keeps the macro running until it has
> > reached the end of my data set. The total number of lines varies from
> > hundreds to thousands.
> >
> > I am sure there is a simple answer but I am having trouble figuring it
> > out.
> > Any help would be greatly appreciated.
> >
> > Steve
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to continue running if error Norvascom Microsoft Excel Programming 6 1st Mar 2010 02:16 AM
User input to continue running the macro FredL Microsoft Access Macros 4 8th Oct 2008 02:01 AM
Continue Macro until list of data is done kdsteff Microsoft Excel Discussion 8 7th Aug 2008 09:28 PM
can I write an Excel macro to pause for data entry then continue? kiwiwaldo Microsoft Excel Misc 3 30th Jun 2008 10:25 AM
Can you pause a macro in excel to input data and continue? =?Utf-8?B?SHV0Y2g=?= Microsoft Excel Misc 1 5th May 2006 06:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:19 AM.