Timestamp issues

sloany101

New Member
Joined
Jan 7, 2023
Messages
35
Office Version
  1. 365
Hello, i have an issue i am looking to resolve, i have a userform that opens up with various options on Sheet3 , the problem is i have a checkbox on it that when selected will copy and paste information to a different sheet (Sheet4) on Sheet 4 in the code is a timestamp code , the code works fine if i am manually typing in the information , but it will not timestamp the target cell after the checkbox macro is finished , can someone help me figure out a code to put in either the check box code or sheet code to trigger an event that causes the target cell to trigger the update after clicking the check box , NOTE** after performing the copy paste function from the userform if i double click the target cell that was pasted to it will trigger the timestamp event**

code for userform is as follows-

VBA Code:
Private Sub CheckBox130_Click()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim n As Long
Dim EmtC As Long
If txtRMBK.Value = "" Or txtRMBK.ListIndex = -1 Then
    MsgBox "Choose Room/Bunk"
    txtRMBK.SetFocus
    Exit Sub
  End If
   With Sheets("Daily POB") 'fit to the name of your sheet
    If txtRMBK.Value < 51 Then
      n = txtRMBK.Value + 2
      .Cells(n, "C").Copy
      
      Else
      n = txtRMBK.Value - 48
      .Cells(n, "M").Copy
    
    End If
  End With

With Sheets("Arrivals-Departures")
    EmtC = .Range("C" & Rows.Count).End(xlUp).Row + 1
    .Range("C" & EmtC).PasteSpecial Paste:=xlPasteValues
End With

With Sheets("Daily POB") 'fit to the name of your sheet
    If txtRMBK.Value < 51 Then
      n = txtRMBK.Value + 2
      .Cells(n, "F").Copy
      
      Else
      n = txtRMBK.Value - 48
      .Cells(n, "P").Copy
    
    End If
  End With
With Sheets("Arrivals-Departures")
    EmtC = .Range("D" & Rows.Count).End(xlUp).Row + 1
    .Range("D" & EmtC).PasteSpecial Paste:=xlPasteValues
End With
With Sheets("Daily POB") 'fit to the name of your sheet
    If txtRMBK.Value < 51 Then
      n = txtRMBK.Value + 2
      .Cells(n, "A").Copy
      
      Else
      n = txtRMBK.Value - 48
      .Cells(n, "L").Copy
    
    End If
  End With
With Sheets("Arrivals-Departures")
    EmtC = .Range("E" & Rows.Count).End(xlUp).Row + 1
    .Range("E" & EmtC).PasteSpecial Paste:=xlPasteValues
End With

Sheets("Arrivals-Departures").Select


Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub



Code for Sheet4 Timestamp is as follows-


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
    If Target.Count > 1 Then Exit Sub    ' this stops code error if more than one cell is changed at once

    If Not Application.Intersect(Target, Range("C5:C49,L5:L49")) Is Nothing Then    ' indicates the Target range
       Target.Offset(, -2) = Format(Now, "m/d/yy hh:mm")
    End If
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
AFAIK, code that alters a sheet won't trigger events like Worksheet_Change event - especially if you disable events! Maybe your solution is to call that event from your click code if you can pass the range. I'm assuming that would be
Worksheet_Change (ActiveSheet.Cells(n, "C"))

Your change code didn't error for me when I did that (but I had to use a number, not n) in the call.
 
Upvote 0
Solution
AFAIK, code that alters a sheet won't trigger events like Worksheet_Change event - especially if you disable events! Maybe your solution is to call that event from your click code if you can pass the range. I'm assuming that would be
Worksheet_Change (ActiveSheet.Cells(n, "C"))

Your change code didn't error for me when I did that (but I had to use a number, not n) in the call.
Holy crap man , your statement "especially if you disable events" was the key , i went back and found that i did not add code to enable events , and once i fixed that it works as i want it to , lmao im dumb , i appreciate your post it helped me solve my problem!!
 
Upvote 0
Glad to help & thanks for the consideration.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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