find first row of a list

L

layla

Hi,
How can I write this:(alist is the name of my list)-I want the first
row of alist
set firstRow=alist.row(1)
 
L

layla

Hi,
How can I write this:(alist is the name of my list)-I want the first
row of alist
set firstRow=alist.row(1)

to be more percise I need the range for the first row of the list
 
J

JE McGimpsey

layla said:
to be more percise I need the range for the first row of the list

Assuming you mean to do this in VBA, there are many, many ways. This is
probably the easiest:

Dim firstRow As Range
Set firstRow = alist.resize(1)

More generally, if n is the row in the list, one way:

Dim firstRow As Range
With alist
Set firstRow = .Cells(n, 1).Resize(1, .Columns.Count)
End With
 
L

layla

Assuming you mean to do this in VBA, there are many, many ways. This is
probably the easiest:

   Dim firstRow As Range
   Set firstRow = alist.resize(1)

More generally, if n is the row in the list, one way:

    Dim firstRow As Range
    With alist
        Set firstRow = .Cells(n, 1).Resize(1, .Columns.Count)
    End With

non of the codes work
 
J

JE McGimpsey

Bob Greenblatt said:
I think you want: set firstrow=alist.row(1).row

Not sure what that would do...

Assuming you meant

set firstrow=alist.rows(1).row

the right side still returns a Long, not an object (which "set"
requires).

And the OP said they wanted "the range for the first row".

My belt and suspenders approach could have been overkill for

Set firstrow = alist.Rows(1)

but I prefer it to using .Rows(1), since it produces a range of cells
rather than a single row object.
 
B

Bob Greenblatt

Not sure what that would do...

Assuming you meant

set firstrow=alist.rows(1).row

the right side still returns a Long, not an object (which "set"
requires).

And the OP said they wanted "the range for the first row".

My belt and suspenders approach could have been overkill for

Set firstrow = alist.Rows(1)

but I prefer it to using .Rows(1), since it produces a range of cells
rather than a single row object.
OOPS, sorry, Yes, of course you are right John, my bad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top