Cancel Word Macro if rule is not met

Version

New Member
Joined
Sep 14, 2017
Messages
3
Good morning,
I'm looking to have a macro stop my copy to word macro if a certain amount of cells are not filled in. Essentially, people need to fill out mandatory cells, so I implemented a simple =IF(COUNTA(E4,E5,E9,E10,E13,E14,E19,E32,E33,E35)<10,"Mandatory Cells Incomplete!","Mandatory Cells Completed!") function to make sure it was greater than the mandatory cells amount.

Now, I'm looking to have this below macro check to make sure that rule is met before running the word macro.


Sub CopyToWord1()


Dim objWord


Dim objDoc


Set objWord = CreateObject("Word.Application")


Set objDoc = objWord.Documents.Add


objWord.Visible = True


Range("A1:B53").Copy

objWord.Activate
objWord.Selection.PasteSpecial dcPasteAll

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Add this to your macro
Code:
If WorksheetFunction.CountA(Range("E4, E5, E9, E10, E13, E14, E19, E32, E33, E35")) < 10 Then
    MsgBox "Mandatory Cells Incomplete!"
    Exit Sub
End If
 
Upvote 0
I'd put it just after this
Code:
Dim objDoc
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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