| 
    
     |  | Buttonを押して A列の合計をさせたいのですが、
 4列目が「ABAB」のデータが
 あるときは、A列の数字をマイナスに変えA列の合計をさせたいのです。
 コード「総合計」は
 一回ボタンを押せば「マイナス処理をした合計」になり正解なのですが
 二回ボタンを押すと「マイナス*マイナス処理」→プラスになり最初の合計と
 後の合計に差がマイナス分の2倍が
 生じます。
 これを避ける方法を教えてください。
 自分なりにSelectCaseを使い
 コード「総合計2」を作成したのですが、SelectCaseの使い方が間違っている
 ためか
 「総合計1」と同じ結果になります。
 アドバイスをよろしくお願いします。
 
 ’・・・・・・・・・・・・・・・・・・・・・・・・・
 Sub 総合計1()
 
 Dim i As Integer, rng As Range, pvl As Long
 pvl = Range("F4").Value
 
 Set rng = Range(Cells(7, 1), Cells(Rows.Count, 1).End(xlUp))
 For i = 7 To Cells(65536, 1).End(xlUp).Row
 If Cells(i, 4) = "ABAB" Then
 Cells(i, 4).Offset(, -3).Formula = Cells(i, 1) * -1
 End If
 Next i
 If rng.Row > 5 Then
 Range("F4").Formula = _
 "=SUBTOTAL(9," & rng.Address & ")"
 MsgBox "総合計は" & Format(Range("F4").Value, "#,##0")
 End If
 With Range("F4")
 If .Value > pvl Then
 Range("F4").Value = pvl
 End If
 End With
 
 End Sub
 ’・・・・・・・・・・・・・・・・
 Sub 総合計2()
 
 Dim i As Integer, rng As Range, j As Integer, MyC As Integer
 For j = 1 To 2
 Select Case j
 Case Is = 1: MyC = -1
 Case Else: MyC = 1
 End Select
 Next j
 
 Set rng = Range(Cells(7, 1), Cells(Rows.Count, 1).End(xlUp))
 For i = 7 To Cells(65536, 1).End(xlUp).Row
 If Cells(i, 4) = "ABAB" Then
 Cells(i, 4).Offset(, -3).Formula = Cells(i, 1) * MyC
 End If
 Next i
 
 If rng.Row > 5 Then
 Range("F4").Formula = _
 "=SUBTOTAL(9," & rng.Address & ")"
 MsgBox "総合計は" & Format(Range("F4").Value, "#,##0")
 End If
 
 End Sub
 ’・・・・・・・・・・・・・・・
 
 |  |