我正在尝试将数组转置为一个范围:
Sub transposearray()
Dim letters As Variant
Dim sht As Workbook
Set sht = Workbooks("report 7-16.xlsx")
letters = Array("a", "b", "c", "d", "e", "f")
sht.Range("AB1:AB6").Value = WorksheetFunction.Transpose(letters)
End Sub
但是当我运行这段代码时,我收到一条消息,提示“运行时错误'438':对象不支持此属性或方法”
我在这里做错了什么?
答案 0 :(得分:3)
您需要一个工作表变量。尝试以下操作(根据需要编辑工作表名称/索引):
Sub transposearray()
Dim letters As Variant
Dim wb As Workbook
Set wb = Workbooks("report 7-16.xlsx")
Dim sht As Worksheet
Set sht = wb.Sheets(1)
letters = Array("a", "b", "c", "d", "e", "f")
sht.Range("AB1:AB6").Value = WorksheetFunction.Transpose(letters)
End Sub