Formula Question

omgitzchris

New Member
Joined
Jun 25, 2008
Messages
6
I know there is a way to do it in VBA code and many other ways.
But my issue is it automatically updates.

I have 4 collumns:
Location//S-1//CSM//SCO
I want to enter in the location in a drop down list, which I know how to do. The thing I'm trying to do is when the Location says To S-1 for example, the date that it is changed "To S-1" the collumn under S-1 will post the date. When location changes to CSM, it will put that day in that collumn, etc.

My issue is that if I use the NOW() or TODAY() function in an IF() then it will update evertime I reopen the file. So the dates won't stay fixed. So if I change the Location to S-1 on the 12th, open it again on the 13th... it will say the 13th not the 12th.
Make sense?

Any help will be great. I have a time line so the quicker the better.

Thanks once again.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
More info:

=IF(B3="To SCO",NOW(),"N/A")
=IF(B3="To SCO",TODAY(),"N/A")

Those are the formulas that I was using, but is there a way to preserve the dates once they are entered into the field?
 
Upvote 0
Hi

Here's some code - right-click on the sheet where you enter these values and select View Code - paste the following in there. Note it assumes that your four columns are A:D and that you have a header in row 1. You may well need to amend these columns to the actual range you have.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
On Error GoTo err_handler
If Not Intersect(Target, Range("A2:A1000")) Is Nothing Then
    Application.EnableEvents = False
    With Target
        Select Case Target.Value
            Case "To S-1"
                .Resize(, 3).Offset(, 1).ClearContents
                .Offset(, 1).Value = Now
            Case "To CSM"
                .Resize(, 3).Offset(, 1).ClearContents
                .Offset(, 2).Value = Now
            Case "To SCO"
                .Resize(, 3).Offset(, 1).ClearContents
                .Offset(, 3).Value = Now
            Case ""
                .Resize(, 3).Offset(, 1).ClearContents
        End Select
    End With
End If
err_handler:
    Application.EnableEvents = True
End Sub
 
Upvote 0
Richard,
You are awesome. The one thing however, is I need to change it to where it will perserve the dates. For example, if I change the location, the previous location's date erases. Is there a way to fix this?

Thanks for your help.
 
Upvote 0
Oh yes of course - sorry, for some reason i thought you would want this functionality! Amended code is:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
On Error GoTo err_handler
If Not Intersect(Target, Range("A2:A1000")) Is Nothing Then
    Application.EnableEvents = False
    With Target
        Select Case Target.Value
            Case "To S-1"
                .Offset(, 1).Value = Now
            Case "To CSM"
                .Offset(, 2).Value = Now
            Case "To SCO"
                .Offset(, 3).Value = Now
            Case ""
                .Resize(, 3).Offset(, 1).ClearContents
        End Select
    End With
End If
err_handler:
    Application.EnableEvents = True
End Sub

If you delete the value in column A, it will still clear all dates in B:D. This can be easily amended if you require.
 
Upvote 0
Was that a serious question? MS killed VBA in Mac Office2008 (I wonder which marketing genius made that decision?) so it won't run under Office2008 I'm afraid.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,220
Members
448,876
Latest member
Solitario

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