Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Sort column without referencing sheet name

I am using a macro to reformat a txt file which was exported from a
proprietary program and opened with Excel. The sort works fine, but I
recorded the macro to get the code and when it sorts by column A, the
recorded code references the specific worksheet name which was automatically
named for the txt file name. Problem is that subsequent txt files will
always have a different name. I just need the wording to make it for
whatever the current sheet is.

TIA,
Kelly


The recorded code came out like this:
Columns("A:F").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Clear
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Add
Key:=Range( _
"A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("QSYSPRT732957").Sort
.SetRange Range("A1:F300")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Sort column without referencing sheet name

Replace

Worksheets("QSYSPRT732957")

with

ActiveSheet

If this post helps click Yes
---------------
Jacob Skaria


"KellyinCali" wrote:

I am using a macro to reformat a txt file which was exported from a
proprietary program and opened with Excel. The sort works fine, but I
recorded the macro to get the code and when it sorts by column A, the
recorded code references the specific worksheet name which was automatically
named for the txt file name. Problem is that subsequent txt files will
always have a different name. I just need the wording to make it for
whatever the current sheet is.

TIA,
Kelly


The recorded code came out like this:
Columns("A:F").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Clear
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Add
Key:=Range( _
"A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("QSYSPRT732957").Sort
.SetRange Range("A1:F300")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Sort column without referencing sheet name

Would this work?

Cells.Select
Selection.Sort Key1:=Range("A1"), SortOn:=xlSortOnValues,
Order:=xlAscending, Header:=xlNo, MatchCase:=False, Orientation:=xlTopToBottom



"KellyinCali" wrote:

I am using a macro to reformat a txt file which was exported from a
proprietary program and opened with Excel. The sort works fine, but I
recorded the macro to get the code and when it sorts by column A, the
recorded code references the specific worksheet name which was automatically
named for the txt file name. Problem is that subsequent txt files will
always have a different name. I just need the wording to make it for
whatever the current sheet is.

TIA,
Kelly


The recorded code came out like this:
Columns("A:F").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Clear
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Add
Key:=Range( _
"A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("QSYSPRT732957").Sort
.SetRange Range("A1:F300")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Sort column without referencing sheet name

Worked... of course! I knew it would be incredibly simple I just didn't know
the syntax. Thanks for indulging my laziness!!

Thanks Jacob!



"Jacob Skaria" wrote:

Replace

Worksheets("QSYSPRT732957")

with

ActiveSheet

If this post helps click Yes
---------------
Jacob Skaria


"KellyinCali" wrote:

I am using a macro to reformat a txt file which was exported from a
proprietary program and opened with Excel. The sort works fine, but I
recorded the macro to get the code and when it sorts by column A, the
recorded code references the specific worksheet name which was automatically
named for the txt file name. Problem is that subsequent txt files will
always have a different name. I just need the wording to make it for
whatever the current sheet is.

TIA,
Kelly


The recorded code came out like this:
Columns("A:F").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Clear
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Add
Key:=Range( _
"A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("QSYSPRT732957").Sort
.SetRange Range("A1:F300")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Sort column without referencing sheet name

Try..

Cells.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlNo, Orientation:=xlTopToBottom

The Sort method expects the below (all of them are optional)
expression.Sort(Key1, Order1, Key2, Type, Order2, Key3, Order3, Header,
OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2,
DataOption3)


If this post helps click Yes
---------------
Jacob Skaria


"KellyinCali" wrote:

Would this work?

Cells.Select
Selection.Sort Key1:=Range("A1"), SortOn:=xlSortOnValues,
Order:=xlAscending, Header:=xlNo, MatchCase:=False, Orientation:=xlTopToBottom



"KellyinCali" wrote:

I am using a macro to reformat a txt file which was exported from a
proprietary program and opened with Excel. The sort works fine, but I
recorded the macro to get the code and when it sorts by column A, the
recorded code references the specific worksheet name which was automatically
named for the txt file name. Problem is that subsequent txt files will
always have a different name. I just need the wording to make it for
whatever the current sheet is.

TIA,
Kelly


The recorded code came out like this:
Columns("A:F").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Clear
ActiveWorkbook.Worksheets("QSYSPRT732957").Sort.So rtFields.Add
Key:=Range( _
"A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("QSYSPRT732957").Sort
.SetRange Range("A1:F300")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Reply
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
Referencing entire column of data from another sheet. gtslabs Excel Worksheet Functions 1 February 1st 09 07:25 PM
Sort List, Create Sheet for each unique item in column, move data J.W. Aldridge Excel Programming 2 April 11th 08 07:18 PM
Referencing date column A & time column B to get info from column TVGuy29 Excel Discussion (Misc queries) 1 January 24th 08 09:50 PM
Button To Sort Sheet Contents On Column? (PeteCresswell) Excel Programming 6 February 9th 07 03:43 PM
Sort referencing incorrect worksheet ingineu Excel Programming 7 February 19th 06 10:55 PM


All times are GMT +1. The time now is 11:33 PM.

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

About Us

"It's about Microsoft Excel"