Conditions Check for a Macro

magnusver

New Member
Joined
Jul 12, 2006
Messages
11
Is there a way to build into a macro a check to see if preset conditions are met and produce an error message if those conditions are not met?

Here is the condition as if it were a formula in Excel:
=IF(COUNTIF(Output!E2:E101,5)<19,"do macro","post an error message with text I can edit")

Here is the existing code for the macro:

Sheets("Output").Select
Range("D2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\nmagnuso\Desktop\Book4.csv", FileFormat:=xlCSV, _
CreateBackup:=False

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="CSV Files(*.csv), *.csv")
If fileSaveName <> False Then
MsgBox "Save as " & fileSaveName
End If

ActiveWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=xlCSV
End Sub



Thanks for your help.

magnusver
 

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.
Hi

Does this approach get you started?


Code:
Sub ccc()
  Dim GetMessageText As String
  Sheets("output").Select
  
 If WorksheetFunction.CountIf(Range("B5:F11"), 5) < 19 Then
   'do macro
 Else
   GetMessageText = InputBox("Enter the message you want to send.")
   MsgBox GetMessageText
End If

End Sub


Tony
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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