stop macro if text is found

mani_singh

Well-known Member
Joined
Jul 24, 2007
Messages
583
i need some script to get a macro to check a cell for a text value = if a certain value is present "no csv file present!" then i need the macro to brake and display and error caption / message on screen!

i need to add this to an existing macro which needs to stop when the text is located :confused:
 

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

What's the entire code you are currently using? Dependent on what it is actually doing, there are several ways you could achieve this.
 
Upvote 0
this is the start of the macro i need the check to be performed at the beginning of the macro prior to anything being performed. the cell ref to be checked is on a sheet called "menu" cell ref=E6 (bear in mind the output text is from a if statement formula in the cell.


Sub pickentries()
'
'

*** I NEED THE CODE CHECKER AND BRAKE HERE ***

Sheets("running").Select

Application.ScreenUpdating = False
Sheets("Baseline Data").Select
Range("H2:H1500").Select
Selection.Copy
Sheets("Hidden").Select
Range("A2").Select
ActiveSheet.Paste

Dim Limit As Long
Dim c As Long
Dim d As Long
Limit = Cells(Rows.Count, 1).End(xlUp).Row
d = 2


 
Upvote 0
OH AND THE TEXT DISPLAYED IS

"No CSV Data Found" - IF STATEMENT = TRUE

"CSV Datafile Present!" - IF STATEMENT = FALSE
 
Upvote 0
Possible code-checker:

Code:
Sub pickentries() 

If Sheets("YourSheet").Range("E6").Value = "No CSV Data Found" Then Exit Sub

'.... rest of your macro
 
Upvote 0
thats worked ! nice one - is there a way i can output a message box before it breaks the code to let the user know whats wrong?
 
Upvote 0
Sure:

Code:
Sub pickentries() 

If Sheets("YourSheet").Range("E6").Value = "No CSV Data Found" Then 
   Msgbox "No Csv Data Found!"
   Exit Sub 
End If

'.... rest of your macro
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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