Solved

Find and continue but if not found End Sub

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 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

11 Experts available now in Live!

Get 1:1 Help Now