Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign an array of values to a range in Excel VBA

Tags:

excel

vba

I am creating column headers for a bunch of columns. I would like to do them in one like below - but I couldn't get the syntax right. Can anyone help?

Range("AB1:AE1").Value = ("UnitPriceUSD","TotalCostUSD","UnitPrice", "TotalCost")
like image 274
Siraj Samsudeen Avatar asked Oct 26 '25 02:10

Siraj Samsudeen


1 Answers

Try this.

Dim arr As Variant
arr = Array("UnitPriceUSD", "TotalCostUSD", "UnitPrice", "TotalCost")

Range("AB1:AE1").Value = arr

Or even simpler:

Range("AB1:AE1").Value = Array("UnitPriceUSD", "TotalCostUSD", "UnitPrice", "TotalCost")
like image 81
mattboy Avatar answered Oct 28 '25 19:10

mattboy