在数组变量中设置元素“m”等于不同列中活动行的值

时间:2013-08-23 19:57:46

标签: arrays excel vba dynamic

我开发了一个循环,它遍历并找到与兼容产品相对应的行项目,兼容产品位于y列循环中的活动行上。我想在我的数组变量中输入产品的名称。我怎样才能做到这一点?

Sub findmultiplemodelid()
Dim item As Variant
ActiveCell.Select
Selection.Offset(0, 1).Select
item = ActiveCell.Value
Sheets("Lights").Select
Rows(3).Select

Dim rangeToSearch As Range
Selection.Find(What:=item, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate
     q = ActiveCell.row()
     z = ActiveCell.Column()
     Dim gmodels() As String
    Range(Cells(q + 1, z), Cells(72, z)).Select
     Set rangeToSearch = Selection
    Set foundRange = rangeToSearch.Find(What:="0", After:=ActiveCell, LookIn:=xlValues,                                                      LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 'First Occurrence
Selection.Find(What:="0", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate
    m = WorksheetFunction.CountIf(Selection, 0)
    ReDim gmodels(0 To m)
    z = 1
    Do Until z > m
    foundRange.Activate
    Set foundRange = rangeToSearch.FindNext(foundRange)
    b = ActiveCell.row
    gmodels(z) = Range(Cells(b, 25).Value)


z = z + 1
    Loop
    foundRange.Activate
  End Sub

我在gmodels上遇到错误(z)=范围(单元格(b,25).Value)

1 个答案:

答案 0 :(得分:1)

使用:

gmodels(z)=Cells(b,25).Value