PDA

View Full Version : Solved: criterion for cell with formula, and the date on another cell



marreco
03-15-2013, 05:56 PM
Hi.

I have a formula in "C1" (= IF (A1 <B1, "Results of the formula", ""), I would like to see "C1" equals "Results formula" then "D1" I get the date current.

I tried and researched often unable to resolve.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Range("C1").Formula = "Results of the formula" Then
Range("D1") = Date
Else
Range("D1") = ""
End If
Application.ScreenUpdating = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C1")) Is Nothing Then
If Range("C1") = "Results of the formula" Then
Range("D1") = Date
Else
Range("D1") = ""
End If
End If
End Sub:banghead:
I will be grateful if someone could help me

Thank you!!

SamT
03-15-2013, 08:32 PM
In the first example, the formula in c1 is
= IF (A1 <B1, "Results of the formula", "")
NOT, "Results of the formula"
Change the sub to read
If Range("C1").Value = "Results of the formula" Then

The second example probably won't ever work because many values on a worksheet change at one time.

marreco
03-16-2013, 04:37 AM
Hi.
I had tried that and it did not work!

SamT
03-16-2013, 04:49 AM
What did happen?

marreco
03-16-2013, 04:51 AM
Hi.

absolutely nothing!

Att

sassora
03-16-2013, 07:17 AM
How about using a formula into D1:

=IF(C1="Results of the formula",TODAY(),"")

marreco
03-16-2013, 07:30 AM
Hi.

I can not use the formula in D1, my idea is to freeze the date if C1 is false.

sassora
03-16-2013, 07:43 AM
Where is the worksheet_change code located?

marreco
03-16-2013, 07:54 AM
Hi.
within the module Sheet1

SamT
03-16-2013, 01:22 PM
It works fine for me, except that it triggers a change event, so it loops continuously. I stopped that by
Application.EnableEvents = False


I just pastedyour code into Sheet1's CodePage then pasted
"Results of the formula"
into C1

marreco
03-16-2013, 01:26 PM
Hi. send me your file

Thank you!!

SamT
03-16-2013, 03:30 PM
Sheet1 is the same as yours, with very minor changes. Sheet2 isan improved version.

marreco
03-16-2013, 03:43 PM
Hi.

Sorry it did not work, I'm using a formula in C1, see Attachment

SamT
03-16-2013, 04:17 PM
You did not read the comments, my friend.

You must comment out the first line that reads "Exit Sub" in order for the macro to run.

This is so you can make changes without having the macro run by removing the comment mark.

The Macro on Sheet 2 is not appropriate at this time. I will need to know which cells are actually changing, other than the results of the formula.

marreco
03-16-2013, 04:27 PM
Hi.

I did it, is not working with the formula in "C1"
I am using a formual in "C1"!!

sassora
03-16-2013, 11:44 PM
Sheet 1 of Don'tWork.xls works for me.

marreco
03-17-2013, 04:59 AM
Hi.
It worked, but I have another problem, I forgot to mention that it is "Now" andnot "Date"

as I do that the time is frozen while A1 <B1?

SamT
03-17-2013, 01:24 PM
Try this one. I changed the macro.

marreco
03-17-2013, 01:53 PM
Hi

Very good!!

Thank you!!