Solved

Find and continue but if not found End Sub

Posted on 2014-02-18
3
184 Views
Last Modified: 2014-02-18
I am using this code to find a word

Range("A:A").Find("Solutions", , xlValues, xlWhole, , , False).Select

and if found I then copy a range from the active cell which works fine

BUT

If I cannot find the word I need to End Sub

Could an expert help me out with this one please.

I am sure it is simple but I just cannot figure it

Thanks
0
Comment
Question by:Jagwarman
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 350 total points
ID: 39866854
this short vba should do this:
dim r as range
set r = Range("A:A").Find("Solutions", , xlValues, xlWhole, , , False)

if r is nothing then exit sub

r.Select

Open in new window


btw, please avoid to "select" a range whenever possible, and just use the range object to do your actions on them.
0
 
LVL 29

Assisted Solution

by:gowflow
gowflow earned 150 total points
ID: 39866863
Sub test()
Dim cCell As Range

Set cCell = Range("A:A").Find("Solutions", , xlValues, xlWhole, , , False)
If Not cCell Is Nothing Then
    MsgBox ("Found " & cCell & " at cell: " & cCell.Address)
Else
    MsgBox ("Did not find any occurence of 'Solutions' in range A:A")
End If


End Sub

Open in new window


pls see the file attached.
gowflow
Find.xls
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39866868
exacly just to show you the possibilities, I choose to put a messagebox but you can do whatever you want like ccell.select if it find it.
regards
gowflow
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now