|
かみちゃんよろしくお願いします。最最終コードです
ponponさん遅くまでありがとうございます。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim hinmei As String, keijyou As String
Dim myRange As Range
Dim endRow As Long
Dim a As Variant
Dim i As Variant
With Target
On Error GoTo errEnd
If .Column <= 1 Or .Column >= 4 Or _
.Row = 1 Then End
Select Case .Column
Case 1
If .Offset(, 1).Value = "" Then Exit Sub
hinmei = .Value
keijyou = .Offset(, 1).Value
GoTo kakuninEvent
Case 2
If .Offset(, -1).Value = "" Then Exit Sub
hinmei = .Offset(, -1).Value
keijyou = .Value
GoTo kakuninEvent
Case 3
If .Value = "式" Then
Application.EnableEvents = False
.Offset(, 1).Value = 1
.Offset(0, 2).Select
Application.EnableEvents = True
End If
End Select
Exit Sub
kakuninEvent:
Set myRange = Range("A2", Cells(Cells.Rows.Count, 1).End(xlUp).Offset(-1)).Resize(, 5)
a = myRange.Value
Application.EnableEvents = False
Range("C" & .Row).ClearContents
Range("E" & .Row).ClearContents
Application.EnableEvents = True
For i = 1 To myRange.Rows.Count
If hinmei = a(i, 1) And keijyou = a(i, 2) Then
Application.EnableEvents = False
Range("C" & .Row).Value = a(i, 3)
Range("E" & .Row).Value = a(i, 5)
Application.EnableEvents = True
Exit For
End If
Next i
End With
errEnd:
End Sub
|
|