VBA return number of rows from an external workbook

Andrew.Noble

New Member
Joined
Sep 18, 2011
Messages
6
Hi

I'm trying to determine the number of rows within a named range in an external workbook, to use in my VBA code.

I have tried the following approach but receive an error:

Code:
Dim rangeRows as Integer
Dim rangeAddress as String
rangeAddress = "'C:\Temp\Book1.xlsx'!NamedRange"
rangeRows = Range(rangeAddress).Rows.Count

Thanks for any help.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi
Please test this:

Code:
Sub Andrew()


    Dim wb As Workbook
    Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & "Data2.xlsm")
    MsgBox wb.Names("Adelaide").RefersToRange.Rows.Count
    wb.Close


End Sub
 
Upvote 0
Hi
Please test this:

Code:
Sub Andrew()


    Dim wb As Workbook
    Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & "Data2.xlsm")
    MsgBox wb.Names("Adelaide").RefersToRange.Rows.Count
    wb.Close


End Sub

Worf, thanks for your reply.

The code works fine, except that it has to open the workbook rather than extract the information while it is closed.

I have found a workaround that does the trick for now.
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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
Back
Top