Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default can I sort using column headings, in a macro, not "a1"

I have written a macro which includes a sort.


Problem happens when I delete a column and then run the macro. The macro
automatically sorts on original column.

Can I use the column heading ie SURNAME to sort. This would be the same
heading after I delete a column, thus solve my problem.

Many thanks

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default can I sort using column headings, in a macro, not "a1"

Hi
in your code (which unfortunately you haven't posted) you may for
example use
- the find method to locate the column
- application.match to locate it

--
Regards
Frank Kabel
Frankfurt, Germany

"John" schrieb im Newsbeitrag
...
I have written a macro which includes a sort.


Problem happens when I delete a column and then run the macro. The

macro
automatically sorts on original column.

Can I use the column heading ie SURNAME to sort. This would be the

same
heading after I delete a column, thus solve my problem.

Many thanks

John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default can I sort using column headings, in a macro, not "a1"

Frank,

This is my code:

Range("A1:AE440").Select

Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub


Problem happens if I delete a column A - F, which I need to do. The macro
will always sort column G, not 'SURNAME' which is in G1.

Once again, many thanks

John


"Frank Kabel" wrote:

Hi
in your code (which unfortunately you haven't posted) you may for
example use
- the find method to locate the column
- application.match to locate it

--
Regards
Frank Kabel
Frankfurt, Germany

"John" schrieb im Newsbeitrag
...
I have written a macro which includes a sort.


Problem happens when I delete a column and then run the macro. The

macro
automatically sorts on original column.

Can I use the column heading ie SURNAME to sort. This would be the

same
heading after I delete a column, thus solve my problem.

Many thanks

John



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default can I sort using column headings, in a macro, not "a1"

use my code and change

Selection.Sort Key1:=rng,

--
Regards,
Tom Ogilvy


"John" wrote in message
...
Frank,

This is my code:

Range("A1:AE440").Select

Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlYes,

_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub


Problem happens if I delete a column A - F, which I need to do. The macro
will always sort column G, not 'SURNAME' which is in G1.

Once again, many thanks

John


"Frank Kabel" wrote:

Hi
in your code (which unfortunately you haven't posted) you may for
example use
- the find method to locate the column
- application.match to locate it

--
Regards
Frank Kabel
Frankfurt, Germany

"John" schrieb im Newsbeitrag
...
I have written a macro which includes a sort.


Problem happens when I delete a column and then run the macro. The

macro
automatically sorts on original column.

Can I use the column heading ie SURNAME to sort. This would be the

same
heading after I delete a column, thus solve my problem.

Many thanks

John





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default can I sort using column headings, in a macro, not "a1"

Not directly unless this is also a defined name (insert=Name=Define)

assume headers in row 1

Dim res as Variant
Dim rng as Range

res = Application.Match("Surname",rows(1),0)
if not iserror(res) then
set rng = rows(1).Cells(1,res)
else
msgbox "Not found"
Exit sub
end if

Range("A1").CurrentRegion.Sort Key1:=rng

--
Regards,
Tom Ogilvy


"John" wrote in message
...
I have written a macro which includes a sort.


Problem happens when I delete a column and then run the macro. The macro
automatically sorts on original column.

Can I use the column heading ie SURNAME to sort. This would be the same
heading after I delete a column, thus solve my problem.

Many thanks

John





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
sort 2 column in the same time "" as dictionary "" Mahmoud Mustafa Excel Worksheet Functions 0 May 1st 10 01:53 PM
Missing sort ascending or descending when go into "data" "sort"? Jason Excel Discussion (Misc queries) 5 September 17th 08 11:57 PM
SORT a column of Texts to follow another "EXACT" order F. Lawrence Kulchar Excel Discussion (Misc queries) 6 September 17th 08 09:14 PM
Adding "letters (column headings)" Rachael Excel Discussion (Misc queries) 7 June 13th 06 05:07 PM
HOW CAN I SORT A "RANKED" COLUMN WITHOUT LOSING THE FORMULA? dbgskid Excel Worksheet Functions 1 May 31st 06 11:50 AM


All times are GMT +1. The time now is 02:52 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"