how to refer to an element in a named range (array/matrix)

Pascalvrolijk

Board Regular
Joined
May 28, 2004
Messages
68
Hi all, i would like to ask your help on this. Been trying, been googling but didnt get it yet..

In Excel I named cell A1 as: selected_fund and I named cells A5:A10 as fundnames. So in excel I want to do a for loop as follows:
for i=1 to 6
[selected_fund].value=[fundnames](i).value
...
next i

This should result in A1=A5.value, then A1=A6.value, ..., then A1=A10.value.
If I replace [fundnames](i).value by [A5], [A6], ..., [A10] it works fine of course, but i want to use reference to an element in an array/matrix.

however i get an error on [fundnames](i).value: "incorrect number of arguments or incorrect property assignment"

Who can help me out to make the reference to an element in [fundnames]?

Thanks in advance,
Kind regards,
Pascal.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
The thing to remember about named ranges is that they are still ranges and must be treated as such. So the loop you describe would look something like this.
VBA Code:
    With [fundnames]
        For i = 1 To .Rows.count
            [selected_fund].Value = .Cells(i, .Column)
        Next i
    End With

The same could also be written in other ways, depending on how you chose to refer to the named range.

VBA Code:
    With Range("fundnames")
        For i = 1 To .Rows.count
            Range("selected_fund").Value = .Cells(i, .Column)
        Next i
    End With

VBA Code:
    With Names("fundnames").RefersToRange
        For i = 1 To .Rows.count
            Names("selected_fund").RefersToRange.Value = .Cells(i, .Column)
        Next i
    End With
 
Upvote 0
Solution
thank you for your reply, from your answer i deducted the following solution:
for i=1 to 6
[selected_fund].value=[fundnames].cells(i).value
...
next i
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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