Private Sub Worksheet_Calculate()
If Range("G1").Value = 1 Then Exit Sub
If Cells(Rows.Count, "C").End(xlUp).Value <> Range("A2").Value Then
Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Value = Range("A1").Value
Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Value = Range("A2").Value
End If
End Sub
I have no way to thank you for all the knowledge you have shared with me.
It works.... Thanks!!!
JC
Take a look at the OnTime method http://www.ozgrid.com/Excel/run-macro-on-time.htm
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime dTime, "MyMacro", , False
End Sub
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:00:05"), "MyMacro"
End Sub
Public dTime As Date
Sub MyMacro()
dTime = Now + TimeValue("00:00:05")
Application.OnTime dTime, "MyMacro"
With Sheets("Sheet1")
.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Value = .Range("A1").Value
.Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Value = .Range("A2").Value
End With
End Sub
Remove your existing code.
Right click the Excel logojust to the left of File on the menu bar, select View Code and paste in
Rich (BB code):Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.OnTime dTime, "MyMacro", , False End Sub Private Sub Workbook_Open() Application.OnTime Now + TimeValue("00:00:05"), "MyMacro" End Sub
Then, whilst still in the code window, Insert > Module and paste in:
Rich (BB code):Public dTime As Date Sub MyMacro() dTime = Now + TimeValue("00:00:05") Application.OnTime dTime, "MyMacro" With Sheets("Sheet1") .Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Value = .Range("A1").Value .Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Value = .Range("A2").Value End With End Sub
Change Sheet1 to the name of your sheet. Save, close and re-open your workbook.
Remove your existing code.
Right click the Excel logojust to the left of File on the menu bar, select View Code and paste in
Rich (BB code):Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.OnTime dTime, "MyMacro", , False End Sub Private Sub Workbook_Open() Application.OnTime Now + TimeValue("00:00:05"), "MyMacro" End Sub
Then, whilst still in the code window, Insert > Module and paste in:
Rich (BB code):Public dTime As Date Sub MyMacro() dTime = Now + TimeValue("00:00:05") Application.OnTime dTime, "MyMacro" With Sheets("Sheet1") .Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Value = .Range("A1").Value .Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Value = .Range("A2").Value End With End Sub
Change Sheet1 to the name of your sheet. Save, close and re-open your workbook.