Adding a second message box to a VBA code!

Anonymous
2024-05-22T17:20:04+00:00

Hi everyone,

I'm not sure if anyone can help me with this one...

I am using the code below to capture the user's name in column AY and the date and time in column AZ.

The second half of the code is triggered if the word "Committed" is selected in the dropdown list in column BS.

This triggers a message box which reads "Your entry has been successfully committed" and then locks down the cells on the entire row.

However, I only want this to happen if the corresponding cell in column J is greater than zero.

If it is blank, I need a warning/message box to advise "Missing Reference", and upon clicking OK, the cell containing "Committed" is cleared and the code ends without locking the cells.

Private Sub Worksheet_Change(ByVal Target As Range)

**If Target.Count > 1 Then Exit Sub** 

**If Not Intersect(Target, Range("I:BS")) Is Nothing Then** 

    **Application.EnableEvents = False** 

     **Application.EnableEvents = False** 

     **Me.Unprotect Password:="441131873"** 

    **Cells(Target.Row, "AY").Value = Environ("UserName")** 

    **Cells(Target.Row, "AZ").Value = Format(Now, "mm/dd/yyyy hh:mm:ss")** 

     **Me.Protect Password:="441131873"** 

    **Application.EnableEvents = True** 

**End If** 

**Dim r As Range** 

**Dim c As Range** 

**Set r = Intersect(Range("BS:BS"), Target)** 

**If r Is Nothing Then Exit Sub** 

**Application.EnableEvents = False** 

**Me.Unprotect Password:="441131873"** 

**For Each c In r** 

    **If UCase(c.Value) = "COMMITTED" Then** 

        **c.Select** 

        **MsgBox "Your entry has been successfully committed!"** 

            **c.EntireRow.Locked = True** 

        **End If** 

**Next c** 

**Me.Protect Password:="441131873"** 

**Application.EnableEvents = True** 

End Sub

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Andreas Killer 144.1K Reputation points Volunteer Moderator
2024-06-03T14:55:26+00:00

Hi Darren,

the best way is to test a code in a new file, in there you can simplify the scenario.
https://www.dropbox.com/scl/fi/pu2q857ycr4puj4dhzqfx/5aebb334-c686-42b7-a6c8-65a599d6d7a9.xlsm?rlkey=fnwajn87qibh2sokyuczcppao&dl=1

As you see, there is no issue in general. If you need further help I need to see your (sample) file.
Why a sample file is important for troubleshooting. How to do it. - Microsoft Community

Andreas.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Oldest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2024-06-03T13:06:01+00:00

    Hi Andreas,

    Thank you so much for taking the time so write this code, and apologies for my late reply (I have been away).

    The code looks excellent and makes sense to me, but unfortunately it doesn't work. I cannot determine why, but it doesn't input the time and date or react to the dropdown list being change to Committed.

    I think this is my fault for requesting such a complicated mechanism, so I may just have find a manual alternative!

    Thank you so much for trying!

    Darren.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-06-04T08:04:55+00:00

    Hi Andreas,

    Thank you so much, the code from within your test workbook has work perfectly!

    I expect I must have copied a space or some other invalid character when copying from the comment thread, my bad!

    Although you may not understand exactly how, I would like you to know that in creating this code you have saved many people a lot of painstaking and time consuming work!

    Thank you again Andreas!

    Was this answer helpful?

    0 comments No comments