PC Review


Reply
Thread Tools Rate Thread

Code to select data

 
 
Anita
Guest
Posts: n/a
 
      28th Mar 2010
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 With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      28th Mar 2010
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" <(E-Mail Removed)> wrote in message
news:06E7F1F1-BB74-4992-A444-(E-Mail Removed)...
> 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 With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      28th Mar 2010
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

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      28th Mar 2010
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

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      28th Mar 2010
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" <(E-Mail Removed)> wrote in message
news:30223B62-C15E-4F61-B82F-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Anita
Guest
Posts: n/a
 
      28th Mar 2010
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" <(E-Mail Removed)> wrote in message
> news:06E7F1F1-BB74-4992-A444-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Code to select cells with data lostandcondfused Microsoft Excel Programming 0 6th Jan 2009 10:19 PM
Code to select cells with data lostandcondfused Microsoft Excel Programming 1 6th Jan 2009 10:01 PM
Select data with SqlDataSource in code behind Arjen Microsoft C# .NET 7 4th Jun 2007 03:12 PM
select data from 2 Dbs in code? Terry Microsoft Access Queries 3 12th Mar 2006 03:54 AM
VBA code to select data from table into combobox Gerry Bennett Microsoft Excel Programming 1 27th May 2005 03:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:23 AM.