| 
    
     |  | Sub henka() Dim k As Long, n As Long, a As Boolean
 
 a = False
 With Worksheets("Sheet1")
 For n = 1 To 49
 If IsNumeric(.Cells(n, 7).Value) And _
 IsNumeric(.Cells(n, 9).Value) Then
 k = .Cells(n, 7).Value - .Cells(n, 9).Value
 If k > 0 And Not a Then
 a = True
 .Cells(n, 9).Interior.ColorIndex = 3
 Else
 a = k > 0
 .Cells(n, 9).Interior.ColorIndex = 2
 End If
 End If
 Next n
 End With
 End Sub
 以上のプログラムがあるとして、赤で表示された数字から2つ目から赤で表示された数字を引いたときの値を求めるプログラムを作成しようとしています。
 以下のようなプログラムを作成しましたが、うまくいきません。
 間違いが分かる方は返信おねがいします。
 PS 引いた値は赤く表示された数字の隣に表示する。
 引く値は赤く表示されたところのみとします。
 
 
 Sub mouke()
 Dim k As Integer
 With Worksheets("Sheet1")
 For n = 1 To 49
 If .Cells(n, 9).Interior.ColorIndex = 3 Then
 k = .Cells(n + 2, 9).Value - .Cells(n, 9).Value
 Cells(n + 2, 10) = k * 1000
 .Cells(n + 2, 10).Interior.ColorIndex = 5
 End If
 Next n
 End With
 End Sub
 
 
 |  |