1Private Sub Worksheet_Change(ByVal Target As Range)
2Application.EnableEvents = False
34 Dim SearchRange As Range
5 Dim ResultRange As Range
6 Dim KeyItem As String
7 Set SearchRange = Range("A1:A1000")
8910With Target
11If .Column = 3 And .Row >= 2 And .Value <> "" Then
12 If .Value <> "" Then
13 .Value = "(" & .Offset(0, -1).Value & ")" & .Value
1415 KeyItem = .Offset(0,-2).Value '符号をキーにして探す
16 Set ResultRange = SearchRange.Find(KeyItem, LookAt:=xlPart)
1718 If Not ResultRange Is Nothing Then '同じ符号がある場合、ここで処理を行いたい
19 .Value = '
202122 Exit Sub
23 End If
24 End If
25End If
26End With
2728Application.EnableEvents = True
29End Sub
30
1Private Sub Worksheet_Change(ByVal Target As Range)
23 Dim SearchRange As Range
4 Dim ResultRange As Range
5 Dim KeyItem As String
6 Dim ResultNumber As String
7 Dim ResultValue As Long
8 Dim Rng As Variant
9 Set SearchRange = Range("A1:A1000")
10 Set ResultRange = Range("F1:F1000")
1112With Target
13If Target.Count > 1 Then Exit Sub
14If .Column = 3 And .Row >= 2 And .Value <> "" Then
1516 Application.EnableEvents = False
1718 If .Value <> "" Then
19 .Value = "(" & .Offset(0, -1).Value & ")" & .Value
2021 KeyItem = .Offset(0, -2).Value '符号をキーにして探す
2223 For Each Rng In SearchRange
2425 If Rng = KeyItem And Rng.Row <> Target.Row Then
2627 ResultNumber = Rng.Offset(0, 2) & Target.Value
28 ResultValue = Rng.Offset(0, 1) + Target.Offset(0, -1).Value
29 Rng.Offset(0, 1) = ResultValue
30 Rng.Offset(0, 2) = ResultNumber
3132 Target.Offset(0, -2).Resize(1, 3).ClearContents
3334 Exit For
35 End If
36 Next
3738 End If
39End If
40End With
4142Application.EnableEvents = True
43End Sub
1Private Sub Worksheet_Change(ByVal Target As Range)
23 Dim SearchRange As Range
4 Dim ResultRange As Range
5 Dim KeyItem As String
6 Dim ResultNumber As String
7 Dim ResultValue As Long
8 Dim Rng As Variant
9 Set SearchRange = Range("A1:A1000")
10 Set ResultRange = Range("F1:F1000")
1112With Target
13If Target.Count > 1 Then Exit Sub
14If .Column = 3 And .Row >= 2 And .Value <> "" Then
1516 Application.EnableEvents = False
1718 If .Value <> "" Then
19 .Value = "(" & .Offset(0, -1).Value & ")" & .Value
2021 KeyItem = .Offset(0, -2).Value '符号をキーにして探す
2223 For Each Rng In SearchRange
2425 If Rng = KeyItem Then
2627 ResultNumber = ResultNumber & Rng.Offset(0, 2).Value
28 ResultValue = ResultValue + Rng.Offset(0, 1).Value
2930 End If
3132 If Rng = "" Then Exit For
3334 Next
3536 For Each Rng In ResultRange
3738 If Rng = KeyItem Or Rng = "" Then
39 Rng.Value = KeyItem
40 Rng.Offset(0, 1) = ResultValue
41 Rng.Offset(0, 2) = ResultNumber
4243 Exit For
44 End If
4546 Next
4748 End If
49End If
50End With
5152Application.EnableEvents = True
53End Sub
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/20 04:40
2021/01/20 04:41
2021/01/20 06:10