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
Solved

Find and continue but if not found End Sub

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
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 demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

809 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