ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to make my code recognize one letter in a text in a cell??? (https://www.excelbanter.com/excel-programming/422647-how-make-my-code-recognize-one-letter-text-cell.html)

Ksenija

How to make my code recognize one letter in a text in a cell???
 
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..




Gary''s Student

How to make my code recognize one letter in a text in a cell???
 
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

--
Gary''s Student - gsnu200827


"Ksenija" wrote:

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..




Ksenija

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


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:

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

--
Gary''s Student - gsnu200827


"Ksenija" wrote:

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..




Gary''s Student

How to make my code recognize one letter in a text in a cell??
 
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.
--
Gary''s Student - gsnu200827


"Ksenija" wrote:



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:

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

--
Gary''s Student - gsnu200827


"Ksenija" wrote:

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..





All times are GMT +1. The time now is 11:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com