How to make my code recognize one letter in a text in a cell???

K

Ksenija

Hi,

I want to write a code that can go thrue all my cells in which there is text
looking somewhat like this:

E304_Gv070524f 3,7_3,7_01
E304_Gv070524o 3,7_3,7_01
E304_Gv070905f 3_3_01
E304_Gv070905o 3_3_01
E304_Gv071220f 2_2_01
E304_Gv071220o 2,1_2_01
E304_Gv071220o 2_2_01
E304_Gv080313f 3,5_3,5_01

in every of these lines there is a "o" or an "f". I want my code to select
all the cells in wich letter "o" is present.. how can I do that?? The letters
are not always in the same place in the cells..
 
G

Gary''s Student

Select the range of cells you want to search and run:

Sub FindO()
Dim r As Range, rfind As Range
Dim v As String
Set rfind = Nothing
Set r = Selection
For Each rr In r
v = rr.Value
If InStr(v, "o") > 0 Then
If rfind Is Nothing Then
Set rfind = rr
Else
Set rfind = Union(rfind, rr)
End If
End If
Next
If rfind Is Nothing Then
Else
rfind.Select
End If
End Sub
 
K

Ksenija

Hi again,
I need more help, am very new at this..
I wrote like this:

Sub FindO()

ActiveCell = L2
Do While Not ActiveCell = Empty

Dim r As Range, rfind As Range
Dim v As String
Set rfind = Nothing
Set r = Selection
For Each rr In r
v = rr.Value
If InStr(v, "o") > 0 Then
If rfind Is Nothing Then
Set rfind = rr
Else
Set rfind = Union(rfind, rr)
End If
End If
Next
If rfind Is Nothing Then
Else
rfind.Select
End If
ActiveCell = ActiveCell.Offset(1, 0)
Loop
End Sub

But now it is only deleting the value in the first cell where there is a
"o", and nothing else..

"Gary''s Student" skrev:
 
G

Gary''s Student

Erase the old versions. Try this:

Sub FindO()
Dim r As Range, rfind As Range
Dim v As String
Set rfind = Nothing
Set r = Range("L2:L65536")
For Each rr In r
v = rr.Value
If v = "" Then Exit For
If InStr(v, "o") > 0 Then
If rfind Is Nothing Then
Set rfind = rr
Else
Set rfind = Union(rfind, rr)
End If
End If
Next
If rfind Is Nothing Then
Else
rfind.Select
End If
End Sub


This version begins with cell L2 and works its way downward until it finds
the first blank.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top