Look for text in column

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi want the code to search for 'Journey Start Event' in column E and if it cannot find it then to exit the macro. I thought the code below would do it, but it doesn't seem to work. Any suggestions? Either to the code below or different code?

thanks

Code:
Dim myCell1 As Range
LastRow2 = ActiveCell.SpecialCells(xlCellTypeLastCell).row
 Set myCell1 = Range("E" & LastRow2)
    Set found = Columns("E").Find(What:="Journey Start Event", LookIn:=xlValues, LookAt:=xlPart)
        If found Is Nothing Then Exit Sub
 

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
Try the following - you didn't have "found" dimmed.

Code:
Dim myCell1 As Range, _
    found   As Range
LastRow2 = Range("E" & Rows.Count).End(xlUp).Row
Set myCell1 = Range("E" & LastRow2)
Set found = Columns("E").Find(What:="Journey Start Event", LookIn:=xlValues, LookAt:=xlPart)
    If found Is Nothing Then Exit Sub
 
Upvote 0
This works fine for me when the text is in column E and when it is not:
Code:
Sub MyDestroyedTurtleOfDoom()
Dim LastRow2 As Integer
Dim myCell1 As Range, found As Range
LastRow2 = ActiveCell.SpecialCells(xlCellTypeLastCell).row
 Set myCell1 = Range("E" & LastRow2)
    Set found = Columns("E").Find(What:="Journey Start Event", LookIn:=xlValues, LookAt:=xlPart)
        If found Is Nothing Then
            Exit Sub
        Else
            MsgBox found.Address
        End If
End Sub
 
Upvote 0
Hi thanks,

That code is working fine. I would like to make one small change though.

I would like the save the file to a folder called bad data and then exit the routine. This is the code to save it

Code:
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:="C:\Bad data\" & ActiveWorkbook.Name

How do I change the if then formula to do this?

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,172
Members
452,893
Latest member
denay

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