1.-
Sub AddColumns()
Dim Sht As Worksheet
Set Sht = ActiveSheet
For i = 7 To 29
Sht.Cells(i, 8).Value = Sht.Cells(i, 7).Value + Sht.Cells(i, 8).Value
Next i
End Sub
2.-
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myRow As Long, myCol As Long
Debug.Print ActiveSheet.Name
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Debug.Print Target.Address
If Not Intersect(Target, Range("J7:J29")) Is Nothing Then
If IsNumeric(Target) Then
myRow = Target.Row
If Cells(myRow, 8).Value = "" Then
myCol = 9
Else
myCol = 8
End If
On Error Resume Next
Application.EnableEvents = False
If Target.Value > Cells(myRow, myCol).Value Then
MsgBox "Value is grather than H or I"
Target.Value = ""
Exit Sub
Else
Cells(myRow, myCol).Value = Cells(myRow, myCol).Value - Target.Value
End If
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End Sub
Bookmarks