2015-06-18 150 views
0

感谢您阅读本文。这是我的问题:我有一张表格上的课程列表,我将它们用作参考,以计算一年内这些课程将出现多少次。但是我无法一次性设置我的变量来获得这些课程之一。这里的代码:使用范围(单元格(),单元格())设置单元格内容的变量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 

感谢您的时间。

+0

如何迭代For Each而不是for循环?这样你可以:'对于myRange中的每个currCell',然后'currCell.Value'会给你课程价值\ text,你可以在范围上使用countif来检查这个值在其中出现的次数,线 –

回答

0

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

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

就足够了。

相关问题