0
我有一個宏,它檢查過濾列結果的每個單元格。它檢查14個不同的範圍。 我想知道,是否有可能以某種方式削減我的代碼,所以我不必複製/粘貼相同的指令到不同的範圍?我正在考慮使用字典,但我不確定這是一個好的解決方案,加上不知道如何混合檢查不同的範圍,並在不同的地方插入結果。下面我爲大家提供一個代碼:對於具有不同範圍的每個細胞?
Sub check_training()
Dim MyRange As Range
Dim rng1 As Range
Dim MyCell As Variant
Dim strAddress As String
Set MyRange = Range([a1], [a1].End(xlDown)).Rows.SpecialCells(xlCellTypeVisible)
'PP 2dni 2007
For Each MyCell In MyRange.Cells
With Range("pp2dni2007")
Set rng1 = .Cells.Find(MyCell.Value)
If Not rng1 Is Nothing Then
If Not IsEmpty(MyCell.Offset(0, liczba).Value) Then
Else
strAddress = rng1.Address
Do
If .Cells.Find(MyCell.Value).Offset(0, 3).Value = "TAK" Then
MyCell.Offset(0, liczba).Value = MyCell.Offset(0, liczba).Value + 1
Else
MyCell.Offset(0, liczba).Value = 0
End If
Set rng1 = .Cells.FindNext(rng1)
Loop While rng1.Address <> strAddress
End If
End If
End With
Next
'PP 3dni 2008
liczba = liczba + 1
For Each MyCell In MyRange.Cells
With Range("pp3dni2008")
Set rng1 = .Cells.Find(MyCell.Value)
If Not rng1 Is Nothing Then
If Not IsEmpty(MyCell.Offset(0, liczba).Value) Then
Else
strAddress = rng1.Address
Do
If .Cells.Find(MyCell.Value).Offset(0, 3).Value = "TAK" Then
MyCell.Offset(0, liczba).Value = MyCell.Offset(0, liczba).Value + 1
Else
MyCell.Offset(0, liczba).Value = 0
End If
Set rng1 = .Cells.FindNext(rng1)
Loop While rng1.Address <> strAddress
End If
End If
End With
Next
(and so on...)
End sub
好的,我可能應該早些時候添加有關此工作簿功能的信息......請點擊此處查看更多詳細信息:http://stackoverflow.com/questions/19248630/excel-countif-macro-with-criteria-resulting-與價值 – lowak
...和你的anwser,我想它可以幫助我。我需要先檢查它。如果您在閱讀給定的鏈接後得到更好的想法,請分享它:) – lowak
好的,我分析了您的代碼。如果我理解了你的anwser,那麼'With Range(「pp2dni2007」)'應該是'With Range(rangeString)',對嗎? – lowak