|
【39744】の関連です。
以前教えていただいたarreyが13個から19個に増えることとなりました。
arreyにMM1 - MM6を追加しました。
また、Loopの制限を > 13から > 19に変えました。
ですが、Mod演算子のところをどう変えればいいかわかりません。どなたかおしえてください。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Stm As String, Etm As String
Dim St As String, Unm As String, ComS As String
Dim Sc As Integer, Ec As Integer
Dim Rc As Long, i As Integer, Col As Integer
Dim Flg As Boolean
Dim MyR As Range, C As Range
Dim NmAry As Variant, ClAry As Variant, Num As Variant
If Intersect(Target, Range("E6:E65536").SpecialCells(-4174)) _
Is Nothing Then Exit Sub
With Target
If .Count > 1 Then Exit Sub
If IsEmpty(.Offset(, -1).Value) Then Exit Sub
Rc = .Row
If Not .Validation.Value Then
Flg = True: GoTo ELine
End If
If .Offset(, -1).Value > .Value Then
Flg = True: GoTo ELine
End If
Range("D6:E65536").SpecialCells(-4174).NumberFormat = "h:mm"
Stm = .Offset(, -1).Text
Etm = .Text
End With
For Each C In Range("F4:AP4")
If C.Text = Stm Then Sc = C.Column
If C.Text = Etm Then Ec = C.Column: Exit For
Next
If Sc = 0 Or Ec = 0 Then
Flg = True: GoTo ELine
End If
Set MyR = Range(Cells(Rc, Sc), Cells(Rc, Ec))
If Not MyR.Count = 0 Then
If WorksheetFunction.CountA(MyR) >= 1 Then
MsgBox "その時間帯は入力済みです", 48
GoTo ELine2
End If
Else
If IsEmpty(MyR.Value) Then
GoTo ELine
End If
End If
ELine:
Application.EnableEvents = False
If Flg Then
MsgBox "入力した値は条件に一致しません。" & _
"クリアして終了します", 48
Else
'↓MM1 - MM6を追加しました
NmAry = Array("AA", "BB", "CC", "DD", "EE", _
"FF", "GG", "HH", "II", "JJ", "KK", "LL", "MM","MM1","MM2","MM3","MM4","MM5","MM6")
ClAry = Array(46, 47, 48, 49, 50, 51, 52, 53, 54, 3, 5, 6, 8,8,8,8,8,8,8)
St = "[氏名の番号を下記の対応表に従って入力して下さい]" & _
vbLf & "AA = 1 : "
'↓Mod演算子のところをどう変えればいいかわかりません。おしえてください。
For i = 1 To UBound(NmAry)
If i Mod 3 = 0 Then
St = St & NmAry(i - 2) & " = " & i - 1 & _
" : " & NmAry(i - 1) & " = " & i & _
" : " & NmAry(i) & " = " & i + 1 & vbLf
End If
Next i
St = Left$(St, Len(St) - 1)
Do
Num = Application.InputBox(St, Type:=1)
If VarType(Num) = 11 Then GoTo ELine2
'↓> 13を > 19に変えました
Loop While CInt(Num) < 1 Or CInt(Num) > 19
Unm = NmAry(CInt(Num) - 1): Col = ClAry(CInt(Num) - 1)
MyR.Value = Unm
MyR.Interior.ColorIndex = Col
ComS = InputBox("コメントを付加したい場合は情報を入力して下さい")
If ComS <> "" Then
Cells(Rc, Sc).AddComment ComS
Cells(Rc, Sc).Comment.Visible = False
End If
End If
ELine2:
Cells(Rc, 4).Resize(, 2).ClearContents
Application.EnableEvents = True
Set MyR = Nothing
End Sub
|
|