|
とりあえず、これで動いているようですが、・・・
あとは、かみちゃんの回答をお待ちください。
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 >= 3 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 .Value = "" Then
Application.EnableEvents = False
Range("C" & .Row).ClearContents
Range("E" & .Row).ClearContents
Application.EnableEvents = True
Exit Sub
End If
hinmei = .Offset(, -1).Value
keijyou = .Value
GoTo kakuninEvent
End Select
Exit Sub
kakuninEvent:
Set myRange = Range("A2", Cells(Cells.Rows.Count, 1).End(xlUp).Offset(-1)).Resize(, 5)
a = myRange.Value
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)
If Range("C" & .Row).Value = "式" Then
Range("D" & .Row).Value = "1"
End If
Application.EnableEvents = True
Exit For
End If
Next i
End With
errEnd:
End Sub
|
|