VBA to stop macro and display error message

kylesom

New Member
Joined
Aug 5, 2009
Messages
37
Hi

I've developed a macro to select and copy data from one workbook to another. When the data is successfully copied the macro displays "Copied to Database" in cell T5.

I'd like to set the macro up to first check that the check cell is empty before proceeding, otherwise stop the macro and display an error prompt box.

I have the following working, however I have no idea how to start to display an error prompt box...

Code:
'Check if rows have been copied already
    Range("T5").Select
    If Selection = "COPIED TO DATABASE" Then Exit Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
'Check if rows have been copied already
    If Range("T5") = "COPIED TO DATABASE" Then 
        MsgBox "This sheet already processed, aborting..."
        Exit Sub
    End If
 
Upvote 0
I have used this code to make sure that a textbox requiring a date is filled out, however, when i then add the date to the text box and try to continue with my macro, the command button that allows this does not do anything. i would like once someone puts the date in, for the macro to continue, any help would be appreciated. here is my code i am using.

Sheets(2).Activate
emptyRow = WorksheetFunction.CountA(Range("D:D")) + 1
Cells(emptyRow, 1).Value = LabelRoute10
Cells(emptyRow, 2).Value = ListBoxAccountName.Value
Cells(emptyRow, 3).Value = DateTextbox.Value

If DateTextbox.Value = vbNullString Then MsgBox "Please input date for this survey", vbCritical
Exit Sub

Unload Me
Brands.Show
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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