Solved

Find and continue but if not found End Sub

Posted on 2014-02-18
3
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 30

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 30

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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,…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

726 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