Solved

Find and continue but if not found End Sub

Posted on 2014-02-18
3
187 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 143

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

740 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