Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help to find the last row of data

Hello
I need someone to help me to write a macro to find the last row in my
data.
I will have two columns A & B with text in it.
Suppose I have data in 5 row, 6th row will be empty. When I run the
macro I want the data to be selected A1:B5. If I enter another item in
my data and run the macro, it should select A1:B6. That is the first
step, then I want the data to be sorted on Column A. I hope this is
clear . I am desperately looking someone to help me.
Thanking you
GT


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Need help to find the last row of data

GT

range("A1:A" & range("A65536").End(xlUp).Row).Select

Regards

Trevor


"gmangad " wrote in message
...
Hello
I need someone to help me to write a macro to find the last row in my
data.
I will have two columns A & B with text in it.
Suppose I have data in 5 row, 6th row will be empty. When I run the
macro I want the data to be selected A1:B5. If I enter another item in
my data and run the macro, it should select A1:B6. That is the first
step, then I want the data to be sorted on Column A. I hope this is
clear . I am desperately looking someone to help me.
Thanking you
GT


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help to find the last row of data

In your case I quess that would be

Sub SelectRows()
Range("A1:B" & Range("A65536").End(xlUp).Row).Select
End Sub


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help to find the last row of data

To be complete on your question:

Sub SelectRowsAndSortOnA()

Range("A1:B" & Range("A65536").End(xlUp).Row).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help to find the last row of data

Thanks to everyone who helped me.. it worked..
Thanks a lot


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Need help to find the last row of data

I suggest the following adjustment...

Sub SelectRowsAndSortOnA()

WITH Range("A1:B" & Range("A65536").End(xlUp).Row)
.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess
.Name = "MyData"
END WITH
End Sub

I dropped the .Select method.
Having named the range, one can more easily use the table in other code

--
Patrick Molloy
Microsoft Excel MVP
----------------------------------
"polletje " wrote in message
...
To be complete on your question:

Sub SelectRowsAndSortOnA()

Range("A1:B" & Range("A65536").End(xlUp).Row).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Need help to find the last row of data

Not even sure we need to worry about the range. I'm sure that the Sort will
pick the correct range provided you refer to a cell within the range,
Hence:

Sub SortOnA()
Range("A1").Sort _
Key1:=Range("A1"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
End Sub

Seems to work OK in my brief test.

If there is definitely a header we should declare "Header:= xlYes," or, if
there's not, "Header:=xlNo,"

Regards

Trevor


"Patrick Molloy" wrote in message
...
I suggest the following adjustment...

Sub SelectRowsAndSortOnA()

WITH Range("A1:B" & Range("A65536").End(xlUp).Row)
.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess
.Name = "MyData"
END WITH
End Sub

I dropped the .Select method.
Having named the range, one can more easily use the table in other code

--
Patrick Molloy
Microsoft Excel MVP
----------------------------------
"polletje " wrote in message
...
To be complete on your question:

Sub SelectRowsAndSortOnA()

Range("A1:B" & Range("A65536").End(xlUp).Row).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub


---
Message posted from http://www.ExcelForum.com/





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
Find, Match data and paste data between two workbooks Chuckak Excel Discussion (Misc queries) 0 September 1st 06 06:59 PM
Find formatting doesn't work: "Excel cannot find data" Kasama Excel Discussion (Misc queries) 1 August 18th 06 01:40 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
The match and lookup functions can find literal data but not the same data referenced from a cell Jeff Melvaine Excel Discussion (Misc queries) 3 April 30th 05 01:29 PM
FIND DATA WITHIN DATA (V-OR-H LOOKUP/FIND/MATCH?) Jaladino Excel Worksheet Functions 0 February 22nd 05 11:22 PM


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