VBA Help! Can a one cell function returning outputs to multiple cells?

SurfsUp123

New Member
Joined
May 24, 2021
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi there,
Can anyone tell me if it is possible to make a function in one cell output to multiple cells, descending vertically.

Here is a simple example where I copy numbers from one column to another, but the for loop just loops it to the bottom of the data set instead of outputting in one cell and then moving down to the next. is it possible to fix this?

VBA Code:
Function myOne(data)

    Dim nrows As Integer
    nrows = data.Rows.Count
    
    'defne array
    Dim DataArray() As Double
    ReDim DataArray(1 To nrows, 1)
    
    'store data into array
    For i = 1 To nrows
        DataArray(i, 1) = data.Cells(i, 1)
    Next i
    
    For i = 1 To nrows
    
        myOne = data.Cells(i, 1)
        
    Next i


End Function
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Only if you have Microsoft365 with the new dynamic arrays, or you array enter the formula into a suitable number of cells initially.
 
Upvote 0
Only if you have Microsoft365 with the new dynamic arrays, or you array enter the formula into a suitable number of cells initially.
Thanks for the quick response. What do you mean by array enter the formula into the cells?
 
Upvote 0
I mean that you select multiple cells, type the formula then press Ctrl+Shift+Enter rather than just Enter. This assumes that your function returns a correctly oriented array. I'm also assuming that you meant you wanted to enter your myOne function as a formula in the sheet. Your function should return the DataArray variable by the way.
 
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

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