VBA help/Insert Date when another cell is changed.

demonfreak

New Member
Joined
Dec 11, 2016
Messages
12
I've found this VBA code online that will insert a date in another cell when any value is entered in the target range.

What I'm wanting to do is the same thing but instead of any value I want a specific value.

I have a column "I" that will only be a "Y" or a "N". I want if the "I" column a "Y" is entered then put today's date. But if the "I" column is "N" or "Blank" then do nothing (no date). I'm having trouble figuring out how to do this.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim A As Range, B As Range, Inte As Range, r As Range
    Set A = Range("A:A")
    Set Inte = Intersect(A, Target)
    If Inte Is Nothing Then Exit Sub
    Application.EnableEvents = False
        For Each r In Inte
            If r.Offset(0, 1).Value = "" Then
               r.Offset(0, 1).Value = Date
            End If
        Next r
    Application.EnableEvents = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try like this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("I:I")) Is Nothing Then
        If UCase(Target.Value) = "Y" Then
            Target.Offset(0, 1).Value = Date
        Else
            Target.Offset(0, 1).Value = ""
        End If
    End If
End Sub
 
Upvote 0
I've noticed an error I get when I have to delete a row which will need to happen from time to time.

Code:
"Run-time error '13':

Type mismatch

When I go into debug it highlights

Code:
If UCase(Target.Value) = "Y" Then

What could I do to fix this?
 
Upvote 0

Forum statistics

Threads
1,213,537
Messages
6,114,216
Members
448,554
Latest member
Gleisner2

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