Creating a timestamp from another cell without using If statment

Parkerpen13

New Member
Joined
Feb 26, 2018
Messages
41
I currently have a workbook that when data is entered in column A it will return a time stamp in column I with the help of the if statement. This works great however it makes my workbook very slowwwww. Is there another way or a VBA code that could do this same thing that could improve my workbook?

Current formula

=IF(A1<>"",IF(I201<>"",I1,NOW()),"")
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Last edited:
Upvote 0
Ok so how would I add that code to this code that is already on that sheet?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("A3:A1000"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="RCFD"
xRg.Locked = True
Target.Worksheet.Protect Password:="RCFD"
End Sub


and add this code to it
Private Sub Worksheet_Change(ByVal Target As Range)

' Automatically place date/time stamp in cells A1:A1000 when a cell in G1:G1000 is manually updated
If Not Intersect(Target, Range("G1:G1000")) Is Nothing Then
Target.Offset(0, -2) = Now
End If

End Sub
 
Last edited:
Upvote 0
Combining two Private Sub Worksheet_Change VBA Codes help

I would like to combine the two following codes together but have been unsucsesful with making both of them to work. Please help

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range
    On Error Resume Next
    Set xRg = Intersect(Range("A3:A1000"), Target)
    If xRg Is Nothing Then Exit Sub
    Target.Worksheet.Unprotect Password:="RCFD"
    xRg.Locked = True
    Target.Worksheet.Protect Password:="RCFD"
 End Sub


and add this code to it


Code:
Private Sub Worksheet_Change(ByVal Target As Range)

 ' Automatically place date/time stamp in cells A1:A1000 when a cell in G1:G1000 is manually updated
    If Not Intersect(Target, Range("G1:G1000")) Is Nothing Then
        Target.Offset(0, -2) = Now
    End If

 End Sub
 
Last edited by a moderator:
Upvote 0
Re: Combining two Private Sub Worksheet_Change VBA Codes help

How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'    On Error Resume Next
    If Not Intersect(Range("A3:A1000"), Target) Is Nothing Then
      Target.Worksheet.Unprotect Password:="RCFD"
      Target.Locked = True
      Target.Worksheet.Protect Password:="RCFD"
   ElseIf Not Intersect(Target, Range("G1:G1000")) Is Nothing Then
      Target.Worksheet.Unprotect Password:="RCFD"
      Target.Offset(0, -2) = Now
      Target.Worksheet.Protect Password:="RCFD"
   End If
 End Sub

Also, when posting code please use code tags, the # icon in the reply window.
 
Upvote 0
Re: Combining two Private Sub Worksheet_Change VBA Codes help

You could try this.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range

    ' Automatically place date/time stamp in cells A1:A1000 when a cell in G1:G1000 is manually updated

    If Not Intersect(Target, Range("G1:G1000")) Is Nothing Then
        Target.Offset(0, -2) = Now
    End If
    
    On Error Resume Next
    Set xRg = Intersect(Range("A3:A1000"), Target)
    If xRg Is Nothing Then Exit Sub
    Target.Worksheet.Unprotect Password:="RCFD"
    xRg.Locked = True
    Target.Worksheet.Protect Password:="RCFD"
    
End Sub
 
Upvote 0
Something like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim xRg As Range
    On Error Resume Next

    Set xRg = Intersect(Range("A3:A1000"), Target)
    If Not xRg Is Nothing Then
        Target.Worksheet.Unprotect Password:="RCFD"
        xRg.Locked = True
        Target.Worksheet.Protect Password:="RCFD"
    End If
    
    If Not Intersect(Target, Range("G1:G1000")) Is Nothing Then
        Target.Offset(0, -2) = Now
    End If
    
End Sub
 
Last edited:
Upvote 0
@Parkerpen13
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.

I have merged both your threads
 
Upvote 0
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Please have patience and allow time for us to see your response and respond to it.
Remember, this is an all volunteer board, and no one is on-line 24x7!
 
Upvote 0
Re: Combining two Private Sub Worksheet_Change VBA Codes help

This code is locking like it should but it is not returning a time stamp in the G column? Any ideas? I have this code in sheet 1.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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