Single calculation

Juan C

Board Regular
Joined
Mar 6, 2009
Messages
131
Help me here...
Is there a way for me to have a formula perform its calculation one time only... meaning that if the precedent data changes it (the formula) won't compute again, thus leaving the previous number it calculated unchange...
 
As C3 should contain a captured value from A2 I suggest using a different cell, say G1 and use the formula

=IF(NOW()>TIMEVALUE("14:00:00"),1,0)

and modify the code to

Code:
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
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I have no way to thank you for all the knowledge you have shared with me.

It works.... Thanks!!!

JC
 
Upvote 0
Hi VoG....

Is there a way to limit the timing in ready the value at A2. Can I read that data every 5 seconds??

Thanks in advance...

JC


I have no way to thank you for all the knowledge you have shared with me.

It works.... Thanks!!!

JC
 
Upvote 0
Sorry VoG.... but this goes above my head. I don't know how to combine the macro you gave me yesterday:

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

With the one you are sending me now...???

Thanks

JC

 
Upvote 0
Remove your existing code.

Right click the Excel logo
excellogofu8.gif
just 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.
 
Upvote 0
I'm getting this message:

Public dTime As Date
Sub MyMacro()
dTime = Now + TimeValue("00:00:05")
Application.OnTime dTime, "MyMacro"
With Sheets("Data 14-15")
.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

It does not work...

Help!!

Remove your existing code.

Right click the Excel logo
excellogofu8.gif
just 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.
 
Upvote 0
I'm getting this Compile Error: Ambiguous name detected: dTime

Any ideas???


Remove your existing code.


Right click the Excel logo
excellogofu8.gif
just 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.
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top