VBA to bring up message box and add data if the answer is yes

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a tab call "Sales"

In Column A in have statuses,

In column J I have if the job is current or completed.

I'd like a macro that could do this,

If a cell in column A is changed to Active then that same row Column J = "Current"
if a cell in column A is Changed to Inactive then I get a message box saying "Is Sale (and the name of the sale from Column D of the same row) Completed?

if they answer Yes then Column J same row = "Completed"
if they answer No "Current"

anything else no change.

Please help if you can

Thanks

Tony
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hello, try this. It goes in the code module for the "sales" sheet.
Also, it assumes that row 1 contains the column headers, with the actual records commencing in row 2.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim lngResult As VbMsgBoxResult
  Dim rngProgress As Range
  Dim rngStatuses As Range
  Dim rngStatus As Range
  Dim rngName As Range
  
  Set rngStatuses = Intersect(Target, Me.Range("A2:A" & Me.Rows.Count))
  
  If Not rngStatuses Is Nothing Then
    For Each rngStatus In rngStatuses
      Set rngProgress = Intersect(rngStatus.EntireRow, Me.Columns("J"))
      Set rngName = Intersect(rngStatus.EntireRow, Me.Columns("D"))
      
      Select Case rngStatus.Value
        Case "Active": rngProgress.Value = "Current"
        Case "Inactive":
          lngResult = MsgBox("Is the sale '" & rngName.Value & "'completed?", vbQuestion + vbYesNo)
          If lngResult = vbYes Then
            rngProgress.Value = "Completed"
          Else
            rngProgress.Value = "Current"
          End If
        Case Else: 'do nothing
      End Select
    Next rngStatus
  End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,271
Members
448,882
Latest member
Lorie1693

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