Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Sort of a problem?

I have a range that is always changing in size. but I want to be able to sort
it!
I've tried recording a Macro to select the bottom, goto the top etc. but I
get an error "Application definded or Object definded error when running it
from a command button.

Can anyone suggest a peice of code to help me please.
The range always starts at A5 and is 8 columns wide but as I said I don't
know howmany rows as the data changes. I will always be needing to sort bu
Column E Descending.

Thanks
Dean
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Sort of a problem?

Hi Dean
sub a()
'This count rows in columns A
Dim colA as double
colA = cells(rows.count, "A").end(xlup).row
'this sort the rang
Range("A5:H" & colA).Sort Key1:=Range("E1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

sub end

regards
Yngve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Sort of a problem?

Assuming the last row of data is followed by an empty row the following
macro will work.

Option Explicit

Sub Test()

Dim iRow As Long
Dim strRange As String
Dim rRange As Range

iRow = 4 ' Note offset 0 corresponds to row 1
Do While Not IsEmpty(Range("A1").Offset(iRow, 0))
iRow = iRow + 1
Loop

strRange = "A5:H" + Trim(Str(iRow))
Set rRange = Range(strRange)
rRange.Sort Key1:=Range("E5"), Order1:=xlDescending

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Sort of a problem?

I got this to partially work for me. I start with a presorted file. The
active cell is mid file, with 20 blank lines after it, but the macro sorts my
whole file, top to bottom (leaving the blank lines, which is OK).
What I need is a sort of the top set of data & then a sort of the bottom set
of data (around the blank lines).

"evgny" wrote:

Hi Dean
sub a()
'This count rows in columns A
Dim colA as double
colA = cells(rows.count, "A").end(xlup).row
'this sort the rang
Range("A5:H" & colA).Sort Key1:=Range("E1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

sub end

regards
Yngve


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 Problem Abdul Shakeel Excel Discussion (Misc queries) 0 February 7th 10 12:22 PM
VBA Sort Problem Tony Excel Discussion (Misc queries) 2 November 18th 09 08:44 PM
Help! I am having a problem with sort! RobertD[_2_] Excel Discussion (Misc queries) 2 August 29th 08 07:56 PM
Sort problem spfas Excel Discussion (Misc queries) 2 December 21st 06 08:25 PM
Sort Problem jdb Excel Discussion (Misc queries) 1 January 10th 05 11:05 PM


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