jojowiththaflow
New Member
- Joined
- Jan 17, 2019
- Messages
- 6
Is there a way to get this code to apply to multiple cells - say C2 through C9?
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rInterest As Range
Set rInterest = Range("H2")
Dim rTotal As Range
Set rTotal = Range("C2")
Dim rList As Range
Set rList = Range("J1")
Dim lRow As Long
' ignore multiple changes, eg, deleting cell contents
If Target.Cells.Count > 1 Then Exit Sub
'Only monitor the cell of interest
If Intersect(Target, rInterest) Is Nothing Then Exit Sub
' only look at numbers
If Not IsNumeric(rInterest.Value) Then Exit Sub
Application.EnableEvents = False
rList.Resize(, 2).Value = Array("Data", "Time Stamp")
lRow = Cells(Rows.Count, rList.Column).End(xlUp).Row + 1
Cells(lRow, rList.Column).Value = rInterest.Value
Cells(lRow, rList.Column + 1).Value = Now
rTotal.Value = rTotal.Value + rInterest.Value
rInterest.Value = ""
rInterest.Select
Application.EnableEvents = True
End Sub
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rInterest As Range
Set rInterest = Range("H2")
Dim rTotal As Range
Set rTotal = Range("C2")
Dim rList As Range
Set rList = Range("J1")
Dim lRow As Long
' ignore multiple changes, eg, deleting cell contents
If Target.Cells.Count > 1 Then Exit Sub
'Only monitor the cell of interest
If Intersect(Target, rInterest) Is Nothing Then Exit Sub
' only look at numbers
If Not IsNumeric(rInterest.Value) Then Exit Sub
Application.EnableEvents = False
rList.Resize(, 2).Value = Array("Data", "Time Stamp")
lRow = Cells(Rows.Count, rList.Column).End(xlUp).Row + 1
Cells(lRow, rList.Column).Value = rInterest.Value
Cells(lRow, rList.Column + 1).Value = Now
rTotal.Value = rTotal.Value + rInterest.Value
rInterest.Value = ""
rInterest.Select
Application.EnableEvents = True
End Sub