Time Stamp

www83

New Member
Joined
Jun 3, 2019
Messages
1
I', still really new to the coding aspect of excel and need some help.

I have created a tracking sheet, what i want is when someone enters their name via a drop down menu in column A that a date and time stamp would appear in column C. i want this code to repeat for when something is placed in Column 7 that a time stamp appears in column D. The code that is not working is below

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRngA As Range
Dim WorkRngB As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRngA = Intersect(Application.ActiveSheet.Range("A:A"), Target)
Set WorkRngB = Intersect(Application.ActiveSheet.Range("F:F"), Target)




xOffsetColumn = 2
Application.EnableEvents = False
If Not WorkRng Is Nothing Then
For Each Rng In WorkRngA
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Date
Rng.Offset(0, xOffsetColumn).NumberFormat = "mm/dd/yyyy"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
End If




'repeat for 2nd range
xOffsetColumn = -2
If Not WorkRngB Is Nothing Then
For Each Rng In WorkRngB
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Date
Rng.Offset(0, xOffsetColumn).NumberFormat = "mm/dd/yyyy"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
End If
Application.EnableEvents = True
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Welcome to the Board!

First thing that stands out is you have a typo in your first block:
Code:
[COLOR=#333333]If Not [/COLOR][COLOR=#ff0000]WorkRng[/COLOR][COLOR=#333333] Is Nothing Then[/COLOR]
[COLOR=#333333]For Each Rng In WorkRngA
[/COLOR]...
You do not have a "WorkRng" variable.

Note that if you turn on the "Option Explicit" setting, it will force you to declare all your variables and catch typos like these.
See here for details: https://www.excel-easy.com/vba/examples/option-explicit.html
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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