Dim C%, r%, rng As Range
Set rng = [F1:K1]
For C = 14 To 14
For r = 11 To 11
If Application.CountIf(rng, Cells(r, C)) >= 1 Then
Cells(4, C) = 1: Exit For
End If
Next r
Next C
Set rng = [F1:K1]
For C = 14 To 14
For r = 12 To 12
If Application.CountIf(rng, Cells(r, C)) >= 1 Then
Cells(5, C) = 1: Exit For
End If
Next r
Next C
Set rng = [F1:K1]
For C = 14 To 14
For r = 13 To 13
If Application.CountIf(rng, Cells(r, C)) >= 1 Then
Cells(6, C) = 1: Exit For
End If
Next r
Next C
Set rng = [F1:K1]
For C = 14 To 14
For r = 14 To 14
If Application.CountIf(rng, Cells(r, C)) >= 1 Then
Cells(7, C) = 1: Exit For
End If
Next r
Next C
Set rng = [F1:K1]
For C = 14 To 14
For r = 15 To 15
If Application.CountIf(rng, Cells(r, C)) >= 1 Then
Cells(8, C) = 1: Exit For
End If
Next r
Next C
Range("N3").Select
ActiveCell.FormulaR1C1 = "=SUM(R[1]C:R[7]C)"
Range("N4").Select
----------------------------------------------------------------
問題一
希望改成下列這樣能縮短程序,卻發現不能累加.不知道該如何處理?
Dim C%, r%, rng As Range
Set rng = [F1:K1]
For C = 14 To 14
For r = 11 To 15 '這裡更改
If Application.CountIf(rng, Cells(r, C)) >= 1 Then
Cells(4, C) = 1: Exit For
End If
Next r
Next C
Dim C%, r%, Rng As Range
Set Rng = [F1:K1]
For C = 14 To 14
For r = 11 To 15
If Application.CountIf(Rng, Cells(r, C)) >= 1 Then
Cells(4, C) = 1: Exit For
End If
Next r
Next C
GBKEE 老師:
您的方式,小弟需要花些時間研究一下,不過好像可以自行延伸到 IV 的位置.
如 剛剛回覆 register313 老師,一樣
其實 n4~n8 是小弟因為不知道如何讓下列程序執行後
Dim C%, r%, Rng As Range
Set Rng = [F1:K1]
For C = 14 To 14
For r = 11 To 15
If Application.CountIf(Rng, Cells(r, C)) >= 1 Then
Cells(4, C) = 1: Exit For
End If
Next r
Next C
在 n3 的位置加總,所以才使用變通的方式,程式分析完後,再加總.不然正常來說只需顯示 n3 的結果即可.
另外可以自行延伸到 IV 的位置.能不能設定到 CN 這各位置. 謝謝您.作者: GBKEE 時間: 2012-1-3 08:32
本帖最後由 GBKEE 於 2012-1-4 21:36 編輯
回復 5#jonn0510
另外可以自行延伸到 IV 的位置.能不能設定到 CN 這各位置
CurrentRegion 屬性 傳回 Range 物件,該物件代表目前的區域。目前區域是指以任意空白列及空白欄的組合為邊界的範圍。唯讀
如資料有從IV延伸到CN 使用CurrentRegion 可達成的作者: jonn0510 時間: 2012-1-4 20:12