如何将值数组分配给Excel VBA中的范围

时间:2021-10-11 21:46:46

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")

1 个解决方案

#1


2  

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")

#1


2  

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")