質問編集履歴
1
回答1を受けて追記いたしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
どうぞよろしくお願いいたします。
|
11
11
|
|
12
12
|
参考までに、条件付き書式自体は下記のようなマクロを使用しています。
|
13
|
-
```
|
13
|
+
```VBA
|
14
14
|
Sub 条件付き書式のセット()
|
15
15
|
|
16
16
|
Dim Con
|
@@ -26,28 +26,27 @@
|
|
26
26
|
'黄緑
|
27
27
|
Con.Interior.ColorIndex = 35
|
28
28
|
Con.StopIfTrue = False
|
29
|
-
|
29
|
+
|
30
|
-
'選択セルを保持
|
31
|
-
Dim rStart As Range
|
32
|
-
Set rStart = ActiveCell
|
33
|
-
Range("範囲_カレンダー").Select
|
34
|
-
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
|
35
|
-
"=AND(TODAY()>=K$2,TODAY()<L$2)"
|
36
|
-
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
|
37
|
-
With Selection.FormatConditions(1).Borders(xlLeft)
|
38
|
-
.LineStyle = xlContinuous
|
39
|
-
.ColorIndex = 3
|
40
|
-
.TintAndShade = 0
|
41
|
-
.Weight = xlThin
|
42
|
-
End With
|
43
|
-
With Selection.FormatConditions(1).Borders(xlRight)
|
44
|
-
.LineStyle = xlContinuous
|
45
|
-
.ColorIndex = 3
|
46
|
-
.TintAndShade = 0
|
47
|
-
.Weight = xlThin
|
48
|
-
End With
|
49
|
-
Selection.FormatConditions(1).StopIfTrue = False
|
50
|
-
'最初の選択セルを選択しなおす
|
51
|
-
rStart.Select
|
52
30
|
End Sub
|
53
31
|
```
|
32
|
+
回答1(ありがとうございます)をうけまして、下記のようか関数を定義してみましたが、
|
33
|
+
エラーが返ってきてしまいます。
|
34
|
+
条件付き書式が設定されており、かつ色がついているセルをカウントするという設定にしていますが、
|
35
|
+
If c.DisplayFormat.Interior.ColorIndex <> xlNone Then
|
36
|
+
の行がうまく効かないようです。何がいけないのでしょうか。。。
|
37
|
+
```VBA
|
38
|
+
Function CountColorA(Rng As Range) As Long
|
39
|
+
Dim c As Range
|
40
|
+
Dim cnt As Long
|
41
|
+
Application.Volatile
|
42
|
+
Col_cnt = 0
|
43
|
+
For Each c In Rng
|
44
|
+
If c.FormatConditions.Count > 0 Then
|
45
|
+
If c.DisplayFormat.Interior.ColorIndex <> xlNone Then
|
46
|
+
cnt = cnt + 1
|
47
|
+
End If
|
48
|
+
End If
|
49
|
+
Next c
|
50
|
+
CountColorA = cnt
|
51
|
+
End Function
|
52
|
+
```
|