output variant into excel using vba

MetLife

Active Member
Joined
Jul 2, 2012
Messages
330
Office Version
  1. 365
Hi,

I have a 10x10 variant that I want to output to the workbook, but am stuck at the moment.


Dim xzy(1 To 100) As Variant


xzy(1) = 5
xzy(2) = 6
Range("A1") = Application.Transpose.xzy

Error = "Invalid number of arguments"
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

I have a 10x10 variant that I want to output to the workbook, but am stuck at the moment.


Dim xzy(1 To 100) As Variant


xzy(1) = 5
xzy(2) = 6
Range("A1") = Application.Transpose.xzy

Error = "Invalid number of arguments"
try this syntax

Code:
Range("A1") = Application.Transpose(xzy)
Transpose is a function, not an object.
 
Upvote 0
If I do that it works but only outputs the first value "5" not the entire array
 
Upvote 0
That works, but my worry is that the size of the range is going to change. Is there a way to do this dynamically?
 
Upvote 0
I have a 10x10 variant that I want to output to the workbook, but am stuck at the moment.

Dim xzy(1 To 100) As Variant
Why do you say you have a "10x10 variant" when your array is declared as one-dimensional?



Dim xzy(1 To 100) As Variant

xzy(1) = 5
xzy(2) = 6
Range("A1") = Application.Transpose.xzy
If you are going to fill the array that way (one element at a time), then if you declare the array this way...

Dim xzy(1 To 100, 1 To 1)

and fill it this way...

xzy(1, 1) = 5
xzy(2, 1) = 6
etc.

then you can do your assignment directly without having to Transpose anything...

Range("A1").Resize(UBound(xzy)) = xzy

Doing it this way, though, does take away your ability to use VB's array functions (such as Filter and Join) as they only work on one-dimensional arrays.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,179
Messages
6,176,911
Members
452,752
Latest member
oliveiralexrui

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