Why does a macro to autopopulate dates sometimes don't autopopulate

MoonLove

New Member
Joined
Dec 31, 2022
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hi Team,

Just a question to get knowledge, I have a macro to autopopulate date when another cell is written, but sometimes it doesnot work.

What could be the reason.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
With such a general question, it is hard to pinpoint the fix. But there is either something not valid about the known cell's population that doesn't trigger your Macro OR there is another criteria that is written in the Macro that hasn't been completed in order for the Macro to be triggered.
 
Upvote 0
Kindly please the code below:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20230101
Dim WorkRng As Range
Dim Rng As Range
Dim dtToday As Date
dtToday = Date

Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("B:B"), Target)
xOffsetColumn = -1
If Not WorkRng Is Nothing Then
    Application.EnableEvents = False
    For Each Rng In WorkRng
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = dtToday
            Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy"
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
    Application.EnableEvents = True
End If
    If Target.Column = 5 Then
        If Target.Value <> "" Then
            Target.Offset(0, 1).Value = "MoonLove"
            Else
            Target.Offset(0, 1).ClearContents
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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