Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Finding Last Cell that Has Data

I have search through prior posting of how to find last row, then sort from
that information, But I must be doing something wrong becasue I still get a
error message. Also the first cell will always be 'A3'.

Here is the code that I have put together:

Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Sheets("XYZ")
Set rngToSort = Range("A3",LastRow = Cells(Rows.Count, "A").End(xlUp).Row)
As Range

rngToSort.Sort Key1:=Range("A3"), order1:=xlAscending, Header:=xlNo

End Sub

Can somebody show me what I'm doing wrong.

Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Finding Last Cell that Has Data

I assume you know how many columns wide you are sorting. I also assume that
your data populates all the way to the bottom of column A (if not then we
need to get a bit more fancy)... You just need to change the "??" to
whichever is your last column...

Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim wks As Worksheet

Set wks = Sheets("XYZ")
Set rngToSort = Range("??3",Cells(Rows.Count, "A").End(xlUp))

rngToSort.Sort Key1:=Range("A3"), order1:=xlAscending, Header:=xlNo

End Sub

--
HTH...

Jim Thomlinson


"caldog" wrote:

I have search through prior posting of how to find last row, then sort from
that information, But I must be doing something wrong becasue I still get a
error message. Also the first cell will always be 'A3'.

Here is the code that I have put together:

Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Sheets("XYZ")
Set rngToSort = Range("A3",LastRow = Cells(Rows.Count, "A").End(xlUp).Row)
As Range

rngToSort.Sort Key1:=Range("A3"), order1:=xlAscending, Header:=xlNo

End Sub

Can somebody show me what I'm doing wrong.

Steve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Finding Last Cell that Has Data

Jim,

After re-reading your post, I realize that I did leave out some information,
which would have been helpful to you.

I am using a userform, which has three fill in boxes. The content goes in
Col A,B,C. After all data is added, by way of a add command button, then on
this same userform, I have my sort button. This is where my troubles start
with my sorting code.

My data will just continue to be added in next empty cell in column A.
Therefore, A3 is the starting point, but Col C will change every time I add
new data.

I also changed my coding to match yours, but the sort didn't happen.

Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Finding Last Cell that Has Data

The code that I presented relies on the fact the the range A3:C100 is the
same block of cells as the range A100:C3. Give this a try. I missed that the
code never referenced the worksheet that is defined.

Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim wks As Worksheet

Set wks = Sheets("XYZ")
with wks
Set rngToSort = .Range(.range("C3"), .Cells(Rows.Count,
"A").End(xlUp))
rngToSort.Sort Key1:= .Range("A3"), order1:=xlAscending, Header:=xlNo
end with

End Sub


--
HTH...

Jim Thomlinson


"caldog" wrote:

Jim,

After re-reading your post, I realize that I did leave out some information,
which would have been helpful to you.

I am using a userform, which has three fill in boxes. The content goes in
Col A,B,C. After all data is added, by way of a add command button, then on
this same userform, I have my sort button. This is where my troubles start
with my sorting code.

My data will just continue to be added in next empty cell in column A.
Therefore, A3 is the starting point, but Col C will change every time I add
new data.

I also changed my coding to match yours, but the sort didn't happen.

Steve

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Finding Last Cell that Has Data

Thanks Jim for the help

Steve

"Jim Thomlinson" wrote:

The code that I presented relies on the fact the the range A3:C100 is the
same block of cells as the range A100:C3. Give this a try. I missed that the
code never referenced the worksheet that is defined.

Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim wks As Worksheet

Set wks = Sheets("XYZ")
with wks
Set rngToSort = .Range(.range("C3"), .Cells(Rows.Count,
"A").End(xlUp))
rngToSort.Sort Key1:= .Range("A3"), order1:=xlAscending, Header:=xlNo
end with

End Sub


--
HTH...

Jim Thomlinson


"caldog" wrote:

Jim,

After re-reading your post, I realize that I did leave out some information,
which would have been helpful to you.

I am using a userform, which has three fill in boxes. The content goes in
Col A,B,C. After all data is added, by way of a add command button, then on
this same userform, I have my sort button. This is where my troubles start
with my sorting code.

My data will just continue to be added in next empty cell in column A.
Therefore, A3 is the starting point, but Col C will change every time I add
new data.

I also changed my coding to match yours, but the sort didn't happen.

Steve

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
Need help finding the last cell w/data Richard Excel Worksheet Functions 4 April 7th 09 02:49 AM
Formula finding last cell in row containing data AbbieW Excel Worksheet Functions 3 July 11th 07 02:03 AM
Formula for finding next cell with data? Tom Watt Excel Discussion (Misc queries) 9 September 15th 06 02:55 PM
Finding matching cell data SRL Excel Worksheet Functions 1 February 24th 06 02:48 PM
Finding last cell with data in a column Nigel Bennett Setting up and Configuration of Excel 2 April 29th 05 08:03 PM


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

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"