Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Code to select data

Hi - I am using v2007 and want to know code for selecting from row 2 to the
end of populated data in a spreadsheet. The length of the data will vary
everytime. Any help gratefully nreceived. Thanks. Anita
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Code to select data

Assuming you mean you want to select entire rows, give this a try...

Dim LastRow As Long
LastRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
If LastRow 1 Then Range("2:" & LastRow).Select

--
Rick (MVP - Excel)



"Anita" wrote in message
...
Hi - I am using v2007 and want to know code for selecting from row 2 to
the
end of populated data in a spreadsheet. The length of the data will vary
everytime. Any help gratefully nreceived. Thanks. Anita


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Code to select data

Sub anita()
Dim r As Range, nLastRow As Long
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
Rows("2:" & nLastRow).Select
End Sub
--
Gary''s Student - gsnu201001


"Anita" wrote:

Hi - I am using v2007 and want to know code for selecting from row 2 to the
end of populated data in a spreadsheet. The length of the data will vary
everytime. Any help gratefully nreceived. Thanks. Anita

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Code to select data

Hi,

Try this

Rows("2:" & Cells.SpecialCells(xlLastCell).Row).Select
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Anita" wrote:

Hi - I am using v2007 and want to know code for selecting from row 2 to the
end of populated data in a spreadsheet. The length of the data will vary
everytime. Any help gratefully nreceived. Thanks. Anita

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Code to select data

That may not work correctly. Try this experiment. Go back to the worksheet
with your sample data and type something into any cell on a row, say, ten
rows down from the current end of your data. Now delete that entry by
selecting the cell and hitting the Delete key on your keyboard. Now run your
code and the selection should go down to the row you entered and then erased
the entry on (which is, if you used my suggestion, ten rows below the shown
end of data).

--
Rick (MVP - Excel)


"Mike H" wrote in message
...
Hi,

Try this

Rows("2:" & Cells.SpecialCells(xlLastCell).Row).Select
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Anita" wrote:

Hi - I am using v2007 and want to know code for selecting from row 2 to
the
end of populated data in a spreadsheet. The length of the data will vary
everytime. Any help gratefully nreceived. Thanks. Anita




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Code to select data

thanks everyone - I'll give it a go...

"Rick Rothstein" wrote:

Assuming you mean you want to select entire rows, give this a try...

Dim LastRow As Long
LastRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
If LastRow 1 Then Range("2:" & LastRow).Select

--
Rick (MVP - Excel)



"Anita" wrote in message
...
Hi - I am using v2007 and want to know code for selecting from row 2 to
the
end of populated data in a spreadsheet. The length of the data will vary
everytime. Any help gratefully nreceived. Thanks. Anita


.

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
VBA: Column Select then Data Select then return to cell A1 James C[_2_] Excel Discussion (Misc queries) 3 February 1st 10 11:35 AM
Code to select cells with data lostandcondfused Excel Programming 0 January 6th 09 10:19 PM
Code to select cells with data lostandcondfused Excel Programming 1 January 6th 09 10:01 PM
VBA code to select data from table into combobox Gerry Bennett Excel Programming 1 May 27th 05 03:57 PM
Select other workbook to select data in a macro. T Tromp Excel Programming 2 September 19th 03 01:43 PM


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