Add a message box to exiting code (below). Msgbox based on a calculated value.

Tanner_2004

Well-known Member
Joined
Jun 1, 2010
Messages
616
Hi All. This macro is launched using a form control button.
Before this routine is run (and I know it is clumsy), I want Excel to check a value cell with a formulae in it (just a simple sum function). If the calculated (not typed-in) value is less than 6 not equal to 6, I want a msgbox to appear that asks the user to complete all fields. If the user completes all fields (which wuil make the value in cell H5 equal to 6), th erest of the procedure will run. Thank you very much.

Sub CopyAndPaste()
'
' CopyAndPaste Macro
'
' Keyboard Shortcut: Ctrl+c
' Copy and paste customer name

Application.ScreenUpdating = False


Range("CustomerName").Select
Selection.Copy
Range("C89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.UnMerge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

' Copy and paste country

Range("CountrySelected").Select
Selection.Copy

Range("D89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.UnMerge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext



End With

'This copies and pastes the role

Range("Role").Select
Selection.Copy
Range("e89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.UnMerge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With


'This copies and pastes the Service Model

Range("ServiceModel").Select
Selection.Copy
Range("f89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.UnMerge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

'This copies and pastes the Spend

Range("Spend").Select
Selection.Copy
Range("g89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext

End With


'This copies and pastes the Function Responses

Range("FunctionResponseRange").Select
Selection.Copy
Range("h89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Application.CutCopyMode = False

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext

End With

Range("c4").Select

End Sub
 
Insert as shown.
Code:
[COLOR=#b22222]Application.ScreenUpdating = False
[/COLOR] If ActiveSheet.Range("H5").Value < 6 Then
  MsgBox "ALL FIELDS MUST BE COMPLETED"
  Exit Sub
 End If
[COLOR=#b22222]Range("CustomerName").Select
[/COLOR]
 
Upvote 0
Worked perfectly...I must have missed the End If. Can't thank you enough. I have another one if you are really up for a challenge(?)!
 
Upvote 0
Glad to help
Additional posts should be on a new thread so others can participate.
Regards, JLG
 
Upvote 0
Thank you. I will re-post under "copying and pasting a range several cell value to the next available row"
 
Upvote 0

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