Issues with timestamp now()

RJGibson

New Member
Joined
May 17, 2019
Messages
14
Hi All,

Any help attained would be great, I am not the best using VBA so hence the query.

I have a sheet where users submit their completed work and a cell calculates the % of work done. I have 4 other cells that have % thresholds from 25%/50%/75%.

Is there a way for me to have a timestamp generated once the threshold ~% of work complete has been added, apologies on the crude example below cant upload images in work :(
[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]% Complete[/TD]
[TD]25%[/TD]
[TD]50%[/TD]
[TD]75%[/TD]
[TD]100%[/TD]
[/TR]
[TR]
[TD]RJ[/TD]
[TD]25[/TD]
[TD]Timestamp[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

The current code we were using is as follows, is there a way to generate the timestamp one time only in each cell?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range: Set A = Range("A3:A6")
Dim v As String
If Intersect(Target, A) Is Nothing Then Exit Sub

Application.EnableEvents = False
v = Target.Value
If v = "25%" Then Target.Offset(0, 1) = Now()
If v = "50%" Then Target.Offset(0, 2) = Now()
If v = "75%" Then Target.Offset(0, 3) = Now()
If v = "100" Then Target.Offset(0, 4) = Now()
Application.EnableEvents = True
End Sub

Regards,
Ray
 
Let's keep walking this back (I am trying to find the "source" of the change).
What is in cell L33? Is this being manually updated, or is it another formula? L33 has another formula
Really, what we are after is the "source" of all these changes. What is the "base" thing that changes that causes all these formulas to update?


And lastly, can you confirm:
- what column has your 25%, 50%, 75%, 100% percentage amounts?
- what column you want the time stamp in?


I appreciate your patience.


L33 is a sum of a range on another worksheet. L33 is updated by formula when work is marked as completed on another sheet manually by a worker when they complete that work. L4 is a set value


The base thing is a worker marks a row complete. that then changes the value of L33. This is turn changes the % number in a cell in Column M


Column O would have a timestamp when a cell in Column M meets the criteria of 25%
Column P would have a timestamp when a cell in Column M meets the criteria of 50%
Column Q would have a timestamp when a cell in Column M meets the criteria of 75%
Column R would have a timestamp when a cell in Column M meets the criteria of 100%


I hope ive explained this better.
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
OK, this could get very tricky.

As we have seen, the Worksheet_Change event procedure only runs when a cell is manually updated. To trigger code to run off of changes due to formulas, that would be the Worksheet_Calculate.
However, there is one major problem with that. Unlike Worksheet_Change, the Worksheet_Calculate event CANNOT identify which cell on the sheet changed. All it knows is that some calculation happened somewhere on the sheet. So, if we use that, we cannot identify which cell's value changed by formula.

So, as I see it, we have two options on how to approach this:
- Create a Worksheet_Change event procedure that runs on the sheet where you are doing the manual data updates (the sheet that the first formulas runs off of). Depending on your data structure, this could get a little tricky in identifying which cell/rows on the other sheet (where the formulas reside) to run against.
- Use a Worksheet_Calculate event procedure that runs on your formula sheets, but every time it runs, it will need to cycle throw ALL the rows it may apply to, and check each one individually to determine which ones need updating. This might work if once your time stamp fields are updated, they should never change (meaning, you would never have a situation where you would want to change a time stamp that is already populated).

So, based on this information, what would you like to do?
 
Upvote 0
I think the second option might work as once the timestamp for a % column a new timestamp for that column should not be generated.
 
Upvote 0
OK, adapting the code that Scott originally wrote for you, try this:
Code:
Private Sub Worksheet_Calculate()

    Application.EnableEvents = False

    Dim v As Range
    For Each v In Range("M33:M55")
        If v = 0.25 And v.Offset(0, 1) = "" Then v.Offset(0, 1) = Now()
        If v = 0.5 And v.Offset(0, 2) = "" Then v.Offset(0, 2) = Now()
        If v = 0.75 And v.Offset(0, 3) = "" Then v.Offset(0, 3) = Now()
        If v = 1 And v.Offset(0, 4) = "" Then v.Offset(0, 4) = Now()
    Next v
    
    Application.EnableEvents = True
    
End Sub
 
Last edited:
Upvote 0
I get a compile error when the formula is updated.

Compile Error


invalid Next control variable reference.
 
Upvote 0
Sorry, typo on my part.

It should be
Code:
Next v
not
Code:
Next cell
 
Upvote 0
You are welcome.
Glad we were able to help you.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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