Previous in Forum: radeon agp card and dell   Next in Forum: Mini Handycam
Close
Close
Close
27 comments
Rating: Comments: Nested
Member

Join Date: Oct 2008
Posts: 7

Excel Question

11/30/2008 8:31 PM

I have a coloum in a excel spreadsheet that inserts the word complete when certain criteria are meet.What I would like to be able to do in the adjancent coloum is to be able to put the date automatically in here when the other coloum changes to complete.

Any ideas

Thanks again

Register to Reply
Pathfinder Tags: Excel Question
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

Good Answers:

These comments received enough positive votes to make them "good answers".

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
5
Power-User

Join Date: Sep 2007
Location: Christchurch, New Zealand
Posts: 168
Good Answers: 18
#1

Re: Excel Question

12/01/2008 10:50 PM

Enter the formula as shown above in Cell B1 and also format that column to be a date. Hope this helps

Register to Reply Good Answer (Score 5)
Member

Join Date: Oct 2008
Posts: 7
#3
In reply to #1

Re: Excel Question

12/01/2008 11:00 PM

Thank you I will try that.Will that put in a new date thou everytime you open excel?

Register to Reply
Guru

Join Date: Aug 2005
Location: Hemel Hempstead, UK
Posts: 5826
Good Answers: 322
#8
In reply to #3

Re: Excel Question

12/02/2008 3:34 AM

I think you've correctly identified a problem with MPM's answer.

If you use FrankGon4s "NOW" and format the cell as time (just to keep it simple), you can quickly experiment with different self referential (or cyclic reference) conditionals, but, I still can't see any way out of this.

__________________
If you spend all your time looking for people and things to complain about: trust me, you will find plenty to complain about.
Register to Reply
Power-User

Join Date: Jun 2007
Posts: 141
Good Answers: 2
#15
In reply to #3

Re: Excel Question

12/02/2008 11:31 AM

I think Randall hit the nail on the head. Every time Excel 'recalculates', it would update any formula to the current date/time. If I understand correctly, once the date is posted, it should not altered further.

Escalus came up with a programmatic approach that looks like it will work well as long as the word "complete" is only used in the specified column, otherwise it would put the date next to where ever it encountered the word "complete". Another possible side effect may be if a cell already has the word "complete", and a formula (or anything else) changed the cell to "complete", e.i. no change at all, if the event for the worksheet would still execute and update an existing date. Perhaps Escalus can comment on this.

Using a combination of formula and VBA code, an 'if' statement could execute code that pastes the current date value to the cell, replacing the 'if' statement in the cell and preventing any further alteration.

Register to Reply
Active Contributor

Join Date: Dec 2007
Location: London, England
Posts: 10
Good Answers: 1
#6
In reply to #1

Re: Excel Question

12/02/2008 3:21 AM

Hi Maths Physics Maniac,

Good answer.

Any ideas of how you can stop the cell formulae result from changing to the current date after being completed some time before?

Its got me stumped, and I don't even play cricket!

Paulus

Register to Reply
2
Guru

Join Date: Aug 2007
Location: Columbia City, Indiana, USA
Posts: 836
Good Answers: 96
#12
In reply to #6

Re: Excel Question

12/02/2008 9:14 AM

Hi Paulus,

I did some playing and think there might be a way:

Here are snaps of the formulae I used:

Then, create a button and set the controls as follows:

Set "calculations" to "iterative" ... if you don't, when you try to use it, it will warn you you are trying to perform a 'circular calculation'.

Then, when the box is 'unchecked', the date and time will count whenever you recalculate.

But, when the box is checked, the cell will lock on that date and time.

In this format, you can 'un-check' the box, and the time will revert to the NOW. If you want that to never happen, used a 'button' instead of a 'check-box'.

I hope this helps some.

Kind regards ...

__________________
"Just when I had all the answers, they changed all the questions"
Register to Reply Good Answer (Score 2)
Active Contributor

Join Date: Dec 2007
Location: London, England
Posts: 10
Good Answers: 1
#13
In reply to #12

Re: Excel Question

12/02/2008 9:24 AM

Hi DCaD,

Thanks for the ideas, I will have a play and see how I get on, it looks promising.

Paulus

Register to Reply
2
Participant

Join Date: Aug 2007
Location: Texas
Posts: 3
Good Answers: 2
#2

Re: Excel Question

12/01/2008 10:58 PM

I wrote a quick test on this.

Assuming C2 has your "complete" or "incomplete", then make the adjoining column with the formula: =IF(C2="complete",NOW()," ")

The command NOW() will give you the date and time. Try just typing =NOW() into a cell and see what pops up. Make sure the cell is set to date and time format, otherwise you will get a string of numbers. Use TODAY() if you only want the date. Date and time is taken from your computer clock.

__________________
Regards, Frank
Register to Reply Good Answer (Score 2)
Associate

Join Date: Mar 2007
Location: La Plata-Argentina
Posts: 47
Good Answers: 1
#9
In reply to #2

Re: Excel Question

12/02/2008 6:59 AM

Hi Frankgon4,

I try your indication with NOW, but can´t set the format cell to date and time at once, it is posible? Could you explain?

Regards

Ernesto1962

Register to Reply
2
Participant

Join Date: Aug 2007
Location: Texas
Posts: 3
Good Answers: 2
#10
In reply to #9

Re: Excel Question

12/02/2008 7:55 AM

Ernesto1962,

Right click on the date and choose format cells. Pick the Tab named 'Number'. Below that will be several options. Choose 'Date' in the left column. In the right column are various formats of date. Scroll down to the format that shows both a date and time. Click 'OK' and your cell will be formatted to date and time.

__________________
Regards, Frank
Register to Reply Good Answer (Score 2)
Associate

Join Date: Mar 2007
Location: La Plata-Argentina
Posts: 47
Good Answers: 1
#11
In reply to #10

Re: Excel Question

12/02/2008 8:03 AM

Frankgon4,

Thanks by your explanation.

My Excel version at office don´t have this format for date.

I will try later at home, I have a laptop with Vista (as look your example).

Regards and thanks again

Ernesto1962

Register to Reply
Guru

Join Date: Aug 2007
Location: Columbia City, Indiana, USA
Posts: 836
Good Answers: 96
#4

Re: Excel Question

12/02/2008 12:20 AM

Hi FITZ,

In addition to the formula shown by MPM, you might also check out the help topics under "Conditional Formatting". This offers some excellent tools as well to visually show states and conditions. In my work, we also track various issues by status, and in addition to something being "complete" or not, it's good to look at "pending", "critical", etc. (for instance), and with conditional formatting you can show everything from "RED/YELLOW/GREEN" (such as a traffic light), or gradients of "Blue to Red" (hot or cold), and so forth.

Excel offers some great visual tools for allowing one to see at a glance if or if not something needs attention.

Good question, and Good Answer by MPM.

Kind regards .......

__________________
"Just when I had all the answers, they changed all the questions"
Register to Reply Score 1 for Good Answer
Member

Join Date: Oct 2008
Posts: 7
#5
In reply to #4

Re: Excel Question

12/02/2008 12:29 AM

I will look at those as well and thanks for the input about the colours

Register to Reply
Member

Join Date: Nov 2008
Posts: 7
#7

Re: Excel Question

12/02/2008 3:26 AM

=If (A1 = "Complete",NOW(),"")

works.

The problem is that now means just that and the date you get will update to the current one whenever the sheet is recalculated. I'm guessing this isn't what you want.

If you want to change the value of a cell to the time at which some condition was first met, you will need to resort to a macro program.

Register to Reply
Member

Join Date: Nov 2008
Posts: 7
#14
In reply to #7

Re: Excel Question

12/02/2008 9:35 AM

Take a deep breath...

For Excel 2003: Paste the code (everything below the stars) underneath into the vbaProject (do tools>customize>tool bars and check the Control Toolbox box. This toolbar has a "View Code" button on it that looks like a magnifying glass and a piece of paper. Press the button and double click the worksheet icon for the sheet you are working in. This opens its VBA code page)

The effect of this code will be to check the sheet whenever it changes and if the value "Complete" appears, it will enter the current date and time into the cell to the right of it as a fixed value that doesn't change. It fails if you change multiple cells at once and doesn't clear dates if the the "Complete" entry is removed

If you are using Excel 2007, the best advice is to revert to 2003 for this kind of thing. Good luck.

*****

Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Count > 1 Then

MsgBox "Automatic date entry on 'Complete' fails when multiple cells are changed. Sorry."

Else

If Target.Value = "Complete" Then Cells(Target.Row, Target.Column + 1) = Now()

End If

End Sub

Register to Reply Score 1 for Good Answer
Power-User

Join Date: Jun 2007
Posts: 141
Good Answers: 2
#16
In reply to #14

Re: Excel Question

12/02/2008 11:39 AM

For Excel 2003, if the cell already has the word "complete", and a formula changes the cell to "complete" (just re-enters what was already there), would the worksheet change event execute altering the already posted date for that cell?

I tried your code using Excel 2007, and the date did update if you retype "Complete" over a cell which already has the word "Complete"

Register to Reply
2
Commentator

Join Date: Oct 2006
Location: East Coast, US
Posts: 94
Good Answers: 3
#19
In reply to #16

Re: Excel Question

12/03/2008 2:00 AM

This will work on the first 100 rows(can be changed to a larger range)

Some other changes may need to be made depending on where the cells are located on the sheet. This is currently set up for column A having the value 'complete', and column B will receive the date only if the cell is empty. It will not overwrite any date already posted to the cells in column B

Private Sub Worksheet_Calculate()
Dim row As Integer
row = 1
Do
If Cells(row, 1) = "complete" And Cells(row, 2) = "" Then Cells(row, 2).Value = Date
row = row + 1
Loop Until row = 100

End Sub

Register to Reply Good Answer (Score 2)
Member

Join Date: Nov 2008
Posts: 7
#22
In reply to #19

Re: Excel Question

12/03/2008 8:56 AM

This is simpler. Counting the number of entries in the column first would let it grow too. Does application.count(range) work in 2007..?

On the downside, simply entering or pasting "Complete" into the A cells doesn't necessarily force recalculation and therefore, in that situation, nothing will happen.

Register to Reply
Power-User

Join Date: Jun 2007
Posts: 141
Good Answers: 2
#25
In reply to #22

Re: Excel Question

12/03/2008 11:38 AM

If you're asking about a Range, then

Range.Count returns number of Cells in Range

Range.Columns.Count returns number of Columns

Range.Rows.Count returns number of Rows

This works for a Range that has a single area, otherwise these return the counts from the first area.

Register to Reply
Commentator

Join Date: Oct 2006
Location: East Coast, US
Posts: 94
Good Answers: 3
#26
In reply to #22

Re: Excel Question

12/04/2008 1:48 AM

A reply to post #14 said it did calculate. I don't have Excel 2007, so I could not properly test the code.

Register to Reply
Member

Join Date: Nov 2008
Posts: 7
#20
In reply to #16

Re: Excel Question

12/03/2008 6:05 AM

Lendog,

Thanks for testing the code in 2007. You are correct and it's not the only weakness either. If the target cell is a formula that produces the word "Complete" it will probably fall over there too. Watching for sheet changes isn't completely fail-safe (the quirks in 2007 may well be different than those in 2003) but it's likelier to trap things than watching for "on calculate".

The code below is better provided that it is some cell in the SAME row as the one you want updated that causes the changes in the FIXED columns used for the word "Complete" and the date entries (assumed to be columns 1 and 2 in the example). It also clears dates if the change made to the row results in the word "Complete" disappearing. This would be un-undoable.

To prevent direct changes to formulas that generate "Complete" and to the date entries themselves, I would normally use ActiveSheet.Unprotect at the begining and and something like ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True at the end. The specific cell protection formats in the sheet need to be set correctly (by hand) and I have no idea what the application looks like.

In general the original point stands; there is no good way to mix dynamic and static data updates in Excel without resorting to code. It is also true that when resorting to code there is no "right" way to do it - just good and bad ways depending on the context and the user. It sounds to me as though if you worked this one through you'd end up with forms and all sorts to stop everything that could go wrong from going wrong. I think the original poster is baffled enough by now by the numerous workarounds on offer...but it was fun anyhow.

Let me know if this is 2007 proof...

;-)

*****

Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim Row As Integer, Col As Integer

If Target.Count > 1 Then MsgBox "Automatic date entry on 'Complete' only changes the top row when multiple cells are changed."

Row = Target.Row

Col = 1

'Change Col to a different value to move the "Complete" column. The offset in the formulas below is +1 - i.e. the next column.

If Cells(Row, Col) = "Complete" And Cells(Row, Col + 1) = "" Then

Cells(Row, Col + 1) = Now()

Else

If Cells(Row, Col) <> "Complete" Then Cells(Row, Col + 1) = ""

End If

End Sub

Register to Reply
Power-User

Join Date: Jun 2007
Posts: 141
Good Answers: 2
#23
In reply to #20

Re: Excel Question

12/03/2008 11:18 AM

Escalus,

When I was playing with the code, I ran across the formula bust, too. It give a type mismatch error when attempting to compare a non-text value to a text value. Sometimes I learn more from bug hunts than anything else...

I ran the code in 2007, and despite everything looking just fine, I ran into the strangest thing. When the event is called, the code executes until it gets to a line that changes the contents of a cell, and the act of changing the cell re-calls the change event. The execution runs to this line:

If Cells(Row, Col) <> "Complete" Then Cells(Row, Col + 1) = ""

If the cell is not "Complete", then blank the next cell. This calls the change event again, which runs this line, makes a change, calls the event, and loops until it errors out with a script out of range. The event calls itself so many times it crashes, and I have to restart 2007 to get the event to call again. I altered the line to

If Cells(Row, Col) <> "Complete" And Cells(Row, Col + 1) <> "" Then Cells(Row, Col + 1) = ""

The event calls itself until no more changes are necessary (twice from what I could see) and exits normally. I did not know (until now) that an event could trigger itself.

I have to agree that there is no right way to do this. I did have fun with it, and enjoyed the challenge. You made me learn something...

Register to Reply
Member

Join Date: Oct 2008
Posts: 7
#27
In reply to #14

Re: Excel Question

12/08/2008 9:14 PM

Thanks for the info.I have not used code or macros much but I tried it and pasted in the code you provided into the worksheet,as per instructions,but I did not get a date to appear in the cell next to the complete.I am using excel 2000 would this make a difference or maby I am doing some thing else wrong?

Thanks

Register to Reply
Power-User

Join Date: Jun 2007
Posts: 141
Good Answers: 2
#17

Re: Excel Question

12/02/2008 12:15 PM

FITZ,

I don't know how adventurous you feel, but I have a approach that will give you a hard date once the target cell is changed to "Complete", and will not update further after that point. First, a piece of VBA code. Hitting Alt F11 will bring up the VBA code window, and double clicking on the sheet you wish to use will open a code window. In the code window, paste the following:

Public Sub PostDate()

With ActiveCell
.Value = Today()
.Copy
.PasteSpecial (xlPasteValues)
End With

End Sub

This code places a formula which gives the current date, and then copies and pastes the date value to the cell. To use this code, use the following statement where needed;

=IF(**address of target cell** = "Complete", PostDate(),"")

Executing "PostDate" from the 'If' Statement replaces the statement with a value representing the current date. If you wish to change the date after this, it must be done manually, or by re-entering the if statement.

Register to Reply Score 1 for Good Answer
Anonymous Poster
#18
In reply to #17

Re: Excel Question

12/02/2008 5:10 PM

Until something more simple is found, why not just enter the date-of-completion, in the appropriate cell, such that it has an apostophe at said date's beginning?...

(e.g.: '12/02/2008 or 'Dec. 12,2008)

Register to Reply
Member

Join Date: Nov 2008
Posts: 7
#21
In reply to #18

Re: Excel Question

12/03/2008 6:08 AM

This guy is worth listening to. Poor automation results in bigger headaches and failures than just living with (and checking for) the human errors you were trying to avoid in the first place.

Register to Reply
Power-User

Join Date: Jun 2007
Posts: 141
Good Answers: 2
#24
In reply to #21

Re: Excel Question

12/03/2008 11:26 AM

It all depends on how many cells we're talking about. Just a few, then entering a date would save the headache. Just a few thousand, maybe the investment in time is justified in the long run. I don't know the full scope of Fitz's problem....

One other thing. My code above should have Now() instead of Today(). My original code was based on Now(), and my last minute substitution for the sake of the post proved to be a fatal error when I went back to test it.

When I went back to the same code, which ran perfect earlier, now has some kind of bug which prevents it from successfully running at all - I have yet to figure it out.

Register to Reply
Register to Reply 27 comments

Good Answers:

These comments received enough positive votes to make them "good answers".

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Copy to Clipboard

Users who posted comments:

Anonymous Poster (1); ArcticZone (2); DCaD (2); ernesto1962 (2); Escalus (5); FITZ (3); frankgon4 (2); Lendog (6); Maths_Physics_Maniac (1); Paulus (2); Randall (1)

Previous in Forum: radeon agp card and dell   Next in Forum: Mini Handycam

Advertisement