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:
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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.
 

mani_singh

Well-known Member
Joined
Jul 24, 2007
Messages
583
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


 

mani_singh

Well-known Member
Joined
Jul 24, 2007
Messages
583
OH AND THE TEXT DISPLAYED IS

"No CSV Data Found" - IF STATEMENT = TRUE

"CSV Datafile Present!" - IF STATEMENT = FALSE
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707

ADVERTISEMENT

Possible code-checker:

Code:
Sub pickentries() 

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

'.... rest of your macro
 

mani_singh

Well-known Member
Joined
Jul 24, 2007
Messages
583
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?
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,054
Messages
5,599,533
Members
414,315
Latest member
Yolanda5050

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
Top