teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

コードを修正しました

2018/09/19 03:39

投稿

h.horikoshi
h.horikoshi

スコア505

answer CHANGED
@@ -25,13 +25,30 @@
25
25
 
26
26
  Dim adrs As Variant: adrs = Split(txt, ",") ' 配列化
27
27
  Dim ix As Long
28
+
29
+ ' ここから置き換え--------------------------------------------------
30
+ txt = ""
28
31
  For ix = 0 To UBound(adrs)
29
- If (Range(adrs(ix)) = "") Then Exit For
32
+ If (Me.Range(adrs(ix)) = "") Then txt = txt & "," & adrs(ix) ' アドレスを収集
30
33
  Next ix
31
- If (ix <= UBound(adrs)) Then
34
+ If (txt <> "") Then
35
+ '
32
- MsgBox ("未入力セルがあります")
36
+ ' アドレスはtxtに収集されています
37
+ '
38
+ txt = Mid$(txt, 2) ' txt先頭の","を除去
39
+ MsgBox ("未入力セルがあります") & vbCrLf & "(""" & txt & "'')" ' メッセージ
33
- Range(クリア用).Interior.Color = RGB(255, 255, 255)
40
+ Range(クリア用).Interior.Color = RGB(255, 255, 255) ' 全クリア
34
- Range(txt).Interior.Color = RGB(255, 255, 153)
41
+ Range(txt).Interior.Color = RGB(255, 255, 153) ' 空白セルだけ色をつける
35
42
  End If
43
+ ' ここまで --------------------------------------------------------
44
+
45
+ ' 旧コード --------------------------------------------------------
46
+ 'For ix = 0 To UBound(adrs)
47
+ ' If (Range(adrs(ix)) = "") Then Exit For
48
+ 'Next ix
49
+ 'If (ix <= UBound(adrs)) Then
50
+ ' MsgBox ("未入力セルがあります")
51
+ ' Range(クリア用).Interior.Color = RGB(255, 255, 255)
52
+ ' Range(txt).Interior.Color = RGB(255, 255, 153)
36
- コード
53
+ 'End If
37
54
  ```

1

jawaさんのご指摘により修正

2018/09/19 03:39

投稿

h.horikoshi
h.horikoshi

スコア505

answer CHANGED
@@ -5,7 +5,14 @@
5
5
  Const 申請区分1用 As String = "D3,D4,D5,D6,D9,D12,E22,F22,D25,D28"
6
6
  Const 申請区分2用 As String = "D5,D6,D11,D16,E34,F34,D36,D37"
7
7
  Const 申請区分3用 As String = "D5,D6,D15,D16,E18,E19,D25,E35,D36"
8
+ '
9
+ ' jawaさんのご指摘により修正。
10
+ ' クリア用には色をつけるセル。つまりを申請区分1用~申請区分3用のセルをすべて
11
+ ' 含める必要があります。この際、漏れが発生しやすいため以下のとおり修正
12
+ '
13
+ ' Const クリア用 As String =
8
- Const クリア用 As String = "D3,D4,D5,D6,D9,D12,E22,F22,D25,D28,D11,D16,E34,F34,D36,D37,D15,E18,E19,E35,D36"
14
+ ' "D3,D4,D5,D6,D9,D12,E22,F22,D25,D28,D11,D16,E34,F34,D36,D37,D15,E18,E19,E35,D36"
15
+ Dim クリア用 As String: クリア用 = 申請区分1用 & "," & 申請区分2用 & "," & 申請区分3用
9
16
 
10
17
  Dim txt As String
11
18
  If (Range("C3") = "申請区分1") Then