+ Reply to Thread
Results 1 to 4 of 4

save one dimensional array to a range

Hybrid View

  1. #1
    Registered User
    Join Date
    04-06-2016
    Location
    NY, NY
    MS-Off Ver
    Office 2010
    Posts
    2

    save one dimensional array to a range

    Can anyone tell me why this particular function doesn't work as a formula on a spreadsheet but it works fine in the immediate window?

    Public Function test() As String

    Range("A1:A3").Value = Application.WorksheetFunction.Transpose(Array("Apple", "Banana", "Orange"))

    test = "Completed"

    End Function

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: save one dimensional array to a range

    If, by "doesn't work as a formula on a spreadsheet ", you mean calling it as a formula in a cell (AKA: A User Defined Function or UDF), then UDFs cannot alter any cell other than the one they were called from. Comment out the Range line and it will return 'Test' perfectly well.
    Last edited by cytop; 05-24-2016 at 09:29 AM.

  3. #3
    Registered User
    Join Date
    04-06-2016
    Location
    NY, NY
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: save one dimensional array to a range

    Thanks, I actually didn't even know that!

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: save one dimensional array to a range

    When called from a spreadsheet formula, functions can return values, but can't do anything to cells.
    Funcitons can't set cell values.

    What you could do is write a UDF like

    Function MyTrial() As Variant
        MyTrial = Array("Apple", "Banana", "Orange")
    End Function
    Then select A1:A3 and enter the array formula =Transpose(MyTrial) with Ctrl-Shift-Enter.

    Or A1:C3 and the formula =MyTrial
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  2. [SOLVED] vertical range into an one-dimensional array
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2013, 03:03 PM
  3. Adding multi dimensional array/range in VBA.
    By amitgaja007 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2011, 09:48 AM
  4. Help with 2 dimensional Array of table for range intersect etc
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2009, 05:14 PM
  5. Writing Multi-Dimensional Array To Range
    By Dan_Dollar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-04-2007, 04:11 PM
  6. [SOLVED] Load excel range into multi dimensional array
    By Rishi Dhupar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2006, 11:55 AM
  7. Transferring part of a multi-dimensional array to a range in VBA
    By Bob J. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1