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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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