Hi,
I cannot figure out why Offset in VBA code gets stuck after running few times...
The section of the code below is supposed to record a timer value from C2 in column G. First it checks if the first record exists in F3:G3. There's no value there yet, so it works: records the timer result after pressing the command button 3 (to reset the timer) and resets timer to 0. After resetting the timer for the second time it recognizes the existing values in F3:G3 and records new values in F4:G4. However, after resetting it for the third time and further, it does not record new values in F5:G5 and further, but overwrites the existing values in F4:G4
Private Sub CommandButton3_Click()
If Range("F3") = "" Then
Range("F3").Value = 1
Range("F3").Offset(0, 1).Value = Range("C2").Value
Else:
Range("F2").End(xlDown).Offset(1, 0).Value = Range("F2").End(xlDown).Value + 1
Range("F2").Offset(0, 1).End(xlDown).Offset(1, 0).Value = Range("C2").Value
End If
Range("C2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime = 0
ResetIt = True
End Sub
I cannot figure out why Offset in VBA code gets stuck after running few times...
The section of the code below is supposed to record a timer value from C2 in column G. First it checks if the first record exists in F3:G3. There's no value there yet, so it works: records the timer result after pressing the command button 3 (to reset the timer) and resets timer to 0. After resetting the timer for the second time it recognizes the existing values in F3:G3 and records new values in F4:G4. However, after resetting it for the third time and further, it does not record new values in F5:G5 and further, but overwrites the existing values in F4:G4
Private Sub CommandButton3_Click()
If Range("F3") = "" Then
Range("F3").Value = 1
Range("F3").Offset(0, 1).Value = Range("C2").Value
Else:
Range("F2").End(xlDown).Offset(1, 0).Value = Range("F2").End(xlDown).Value + 1
Range("F2").Offset(0, 1).End(xlDown).Offset(1, 0).Value = Range("C2").Value
End If
Range("C2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime = 0
ResetIt = True
End Sub