使用带有范围的单元格内容设置变量(Cells(),Cells())Excel VBA

时间:2015-06-18 12:08:42

标签: excel vba excel-vba

无论如何,感谢您阅读本文。这就是我的问题:我在一张纸上列出了一系列课程,并且我将它们作为参考来计算这些课程在一年内出现的次数。但我无法设置我的变量来同时获得其中一门课程。这是代码:

lr = ws.Cells(1, 1).End(xlDown).Row

ReDim x(lr - 1)
For i = 1 To (lr - 1)
    k = ws.Range(Cells(1 + i, 1), Cells(1 + i, 1)).Text
        For Each sheets In wb.sheets
            With sheets.Range("A1:J86")
                Set rng = .Find(k, sheets.Cells(1), xlValues, xlWhole, xlByRows, xlPrevious, False)
                    If Not rng Is Nothing Then
                        v = v + 1
                    End If
            End With
        Next sheets
    x(i) = (v - 1)
    v = 0
Next

感谢您的时间。

1 个答案:

答案 0 :(得分:0)

只有一个单元格不需要Range(Cells(), Cells())

k = ws.Cells(1 + i, 1).Text

就足够了。