繁体   English   中英

错误424对象必需错误

[英]error 424 object required error

我正在尝试将一系列单元格中的值输入到数组中。

以下代码给我一条错误424对象要求的消息。 请帮忙

feedingtypes() = wbfeedingtypes.Range("A2:A" & lrowfeedingtypes).Value

我已经运行并测试了以下内容

Sub RangeToArray()
  Dim i As Long
  Dim ws As Worksheet
  Dim myRange As Range, cell As Range
  Dim feedingtypes() As String

  Set ws = ThisWorkbook.Worksheets(1)
  Set myRange = ws.Range("A1:A20")
  i = 1

  For Each cell In myRange
    'Only add non blanks
    If cell.Value <> "" Then
      'Resize the array each time another cell is added
      ReDim Preserve feedingtypes(i)
      feedingtypes(i) = cell.Value
      i = i + 1
    End If
  Next cell
End Sub

我相信这就是你要找的东西:

Dim feedingtypes() As Variant
feedingtypes = wbfeedingtypes.Sheets(1).Range("A2:A" & lrowfeedingtypes)

请注意,变量名称后面的第二行代码中没有括号。 根据您的评论,似乎只有一个工作表。 因此,您也可以按编号参考图纸。 我相应地更改了答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM