Lookup last valid row

grahambza

New Member
Joined
Sep 7, 2005
Messages
19
Hi
I have a list of approx 130 suppliers that I want to use as my list for a drop down box
In my range for the drop down I make the range bigger in case I add suppliers

What I want to do is
- have a formula work out which is the last valid row
- use this cell ref in my sort and range formulas

Any tips?

Graham
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

grahambza

New Member
Joined
Sep 7, 2005
Messages
19
I used countif(A1:A200,"*") to get the answer

How do i use this result in a sort macro

Currently my macro contains
ActiveWorkbook.Names.Add Name:="Suppliers", RefersToR1C1:= _
"=Sheet3!R1C1:R200C1"

Any help is appreciated
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Do you mean that you need VBA to return the last filled row in column A? If so

Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
 

davesweep

Well-known Member
Joined
Apr 30, 2007
Messages
510

ADVERTISEMENT

Hi,

Create a named range. If your data is in column A for example, use
=OFFSET($A$1,0,0,1,COUNTA(Sheet1!A:A))
then use the range name as the definition for your validation list.
 

grahambza

New Member
Joined
Sep 7, 2005
Messages
19
Thanks everyone

How do I use the result of the Last Row in a formula?

I tried this:

Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:LR").Select
ActiveWorkbook.Names.Add Name:="Suppliers", RefersToR1C1:= _
"=Sheet3!R1C1:LRC1"
'"=Sheet3!R1C1:R200C1"

And of course I got an error in the range selection

Any help is appreciated
 

grahambza

New Member
Joined
Sep 7, 2005
Messages
19

ADVERTISEMENT

Please ignore my last post
I worked out how to use the offset suggested by VOG II - and now have another problem which i will post separately
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try this

Code:
Sub test()
Dim LR As Long
With Sheets("Sheet1")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    ThisWorkbook.Names.Add Name:="Suppliers", RefersTo:=.Range("A1:A" & LR)
End With
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,373
Messages
5,836,875
Members
430,460
Latest member
cristian270

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top