使用范围(单元格(),单元格())设置具有单元格内容的变量 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

谢谢你的时间。

不需要只对一个单元格进行Range(Cells(), Cells())

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

就足够了。

最新更新