Lookup last valid row

grahambza

New Member
Joined
Sep 7, 2005
Messages
17
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
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

grahambza

New Member
Joined
Sep 7, 2005
Messages
17
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
17
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
17

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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,315
Messages
5,600,908
Members
414,415
Latest member
joshuaba

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