VBA Range question

remstadt

New Member
Joined
Jan 24, 2014
Messages
3
I am having trouble assigning to a range. Assume that I am passing a column range into the function. How can I modify the following to get it to assign a value to my_range?

Function assign_me(ByRef my_range As Range) As Double
Dim my_array As Variant
my_array = myrange.Value
For I = 1 To UBound(my_array, 1)
my_range(I, 1).Value = I
Next I
assign_me = 0#
End Function
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you are trying to call that function from a cell, it will not work.
 
Upvote 0
Is there a way to do it? I would like to make a function that is vector valued or array valued, and callable from the spreadsheet.
 
Upvote 0
Functions should just return values. Don’t attempt to manipulate other cells.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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