Add Message box to VBA code

posfog

Board Regular
Joined
Jun 2, 2009
Messages
171
Hi All,
I have some coding that allows me to copy data from one sheet to another, but i want the same coding to look at Cell M4 and display a Message box if Cell M4 contains the wording "Select Variant"


Is this possible and where would it need to be within the coding (shown below sorry for long coding)


Sub ADDRECORD()







Dim src As Worksheet
Dim dst As Worksheet
Dim rw As Long

Application.ScreenUpdating = False

' Set source and destination sheets
Set src = Sheets("TOUCH SCREEN")
Set dst = Sheets("RAW DATA")

' Find next available row on destination sheet
rw = dst.Cells(Rows.count, "A").End(xlUp).Row + 1

' Populate values on destination sheet
dst.Cells(rw, "A") = src.Range("A101")
dst.Cells(rw, "B") = src.Range("B101")

Application.ScreenUpdating = True

End Sub


Regards
 
unfortunately not as i need the user to select other items within the sheet which M4 is looking at (which if these items are not completed correctly the "Select Variant")
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
unfortunately not as M4 is dependent on other cells within the same sheet.

So i would need the end user to make the changes and for the script to run again
 
Upvote 0
Try this:
Script will show Message and then stop if:

Code:
Sub ADDRECORD()
    'Modified 1-31-18 10:45 PM EST
    Dim src As Worksheet
    Dim dst As Worksheet
    Dim rw As Long
    Application.ScreenUpdating = False
' Set source and destination sheets
    Set src = Sheets("TOUCH SCREEN")
    Set dst = Sheets("RAW DATA")
' Find next available row on destination sheet
    rw = dst.Cells(Rows.Count, "A").End(xlUp).Row + 1
' Check M4
    If src.Range("M4") = "Select Variant" Then
        MsgBox "Tab " & src.Name & " contains 'Select Variant'", vbInformation, "Select Variant found...": Exit Sub
    ElseIf dst.Range("M4") = "Select Variant" Then
        MsgBox "Tab " & dst.Name & "contains 'Select Variant'", vbInformation, "Select Variant found..."
    End If
' Populate values on destination sheet
    dst.Cells(rw, "A") = src.Range("A101")
    dst.Cells(rw, "B") = src.Range("B101")
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here too, glad you're sorted.

You can ditch the:

Code:
    ElseIf dst.Range("M4") = "Select Variant" Then
        MsgBox "Tab " & dst.Name & "contains 'Select Variant'", vbInformation, "Select Variant found..."

I only put this in as the sheet M4 was on wasn't specified.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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