【发布时间】:2020-09-18 23:10:04
【问题描述】:
我敢肯定,存在一个相当简单的解决方案!
我将数据保存在一个 Excel 列中,该列可以包含一对多条目。我需要将其添加到数组中。
当有 2 个或更多条目时,我的代码运行良好。
但是,当只有一个值时,我会得到类型不匹配。我尝试了许多解决方法,但没有成功!代码如下:
Option Explicit
Private Namez() As Variant
With Sheets("Names")
Range("A1").Select
Lrow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
If Lrow = 1 Then ' Attempt at coding for a single value
Namez = Sheets("Names").Range("A1").Value ' Here's where it errors
Else
Namez = Sheets("Names").Range("A1:A" & Lrow).Value ' Or here (before adding the LRow = 1 line)
End If
【问题讨论】:
-
去掉
()你不能给数组赋值:Private Namez As Variant