how to recognize a specific letter in a cell

K

Ksenija

Hi,

I have a lots of cells in which there it written things like these:

E2245_Gv070830f 3,5_3,5_01
E224_Gv070830o 3,5_3,5_01
E224_Gv071220f 4_4_01

I want to select all cells in which letter "o" or "f" is present. How can i
write this in code?? these letters can have different places in the cell..
 
J

Joergen Bondesen

Hi Ksenija

Try below:

Option Explicit


'----------------------------------------------------------
' Procedure : TestForLetter
' Date : 20090119
' Author : Joergen Bondesen
' Modifyed by : Select cell with Array Letter
' Purpose :
' Note :
'----------------------------------------------------------
'
Sub TestForLetter()
Dim TestLetter As Variant
TestLetter = Array("o", "f")

Dim RRange As Range
Set RRange = Selection

Dim cell As Range
For Each cell In RRange
Dim x As Long
For x = LBound(TestLetter) To UBound(TestLetter)
Dim Testx As Long
Testx = InStr(1, cell, TestLetter(x))
If Testx <> 0 Then x = UBound(TestLetter)
Next x

If Testx <> 0 Then
Dim SelCell As Range
If SelCell Is Nothing Then
Set SelCell = cell
Else
Set SelCell = Union(SelCell, cell)
End If
End If
Next cell

If Not SelCell Is Nothing Then
SelCell.Select
End If

Set RRange = Nothing
Set SelCell = Nothing
End Sub
 

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