Add message box

Rob_010101

Board Regular
Joined
Jul 24, 2017
Messages
198
Office Version
  1. 365
Platform
  1. Windows
Hello,

The below macro currently works perfectly and moves a line of data based on the selection from a drop-down menu (data validation list).

I'd like to add a simple "are you sure you want to proceed" "yes" "no" style button message box when the user selects the item.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
 On Error Resume Next
    Sheet1.ShowAllData
  On Error GoTo 0
 
  Dim fromRow%
  Dim archiveRow%
  Dim strMatch As String
  Dim wsTarget As Worksheet
  Dim blnMove As Boolean
  Dim blnOnlyValues As Boolean
  
  If Target.Cells.Count > 1 Then Exit Sub

  If Not Application.Intersect(Target, Range("H7:H2000")) Is Nothing Then
    blnOnlyValues = False
    Select Case UCase(Target.Value)
      Case "COMPLETE"
        Set wsTarget = ThisWorkbook.Worksheets("Completed")
        blnMove = True
        blnOnlyValues = True
          End Select
    If blnMove Then
      fromRow = ActiveCell.Row
      With wsTarget
        If .FilterMode Then
          strMatch = "match" & Replace("(2,1/(a:a>""""),1)", "a:a", .AutoFilter.Range.Cells(1).EntireColumn.Address(0, 0, 1, 1))
          archiveRow = Evaluate(strMatch) + 1
        Else
          archiveRow = wsTarget.Cells(wsTarget.Rows.Count, 1).End(3).Row + 1
        End If
      End With
Range(Cells(fromRow, 1), Cells(fromRow, 8)).Copy wsTarget.Cells(archiveRow, 1)
With wsTarget
    .Range(.Cells(archiveRow, 1), .Cells(archiveRow, 1)).FormatConditions.Delete
End With
If blnOnlyValues Then wsTarget.Cells(archiveRow, 1).Resize(1, 20).Value = Cells(fromRow, 1).Resize(1, 20).Value
Application.EnableEvents = False
Rows(fromRow).EntireRow.Delete
Application.EnableEvents = True
Set wsTarget = Nothing
    End If
  End If

End Sub

I should add, I have this code

VBA Code:
ans = MsgBox("are you sure you want to continue ?", vbYesNo)
If ans = vbNo Then Exit Sub

But I need to be able to move the line back from the other sheet which I have used the same code for but in reverse if a user does this incorrectly and this causes strange behavior
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
The code you have :

VBA Code:
ans = MsgBox("are you sure you want to continue ?", vbYesNo)
If ans = vbNo Then Exit Sub

Seems fine for that purpose.
 
Upvote 1
If you put this confirmation at the beginning of the code before the meat of the code runs instead of "after the fact", then you shouldn't need to reverse anything.
 
Upvote 1
Solution

Forum statistics

Threads
1,223,880
Messages
6,175,155
Members
452,615
Latest member
bogeys2birdies

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