Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying IF/Then to pick out individual letters in a cell? 1

Status
Not open for further replies.

Forrest77

Technical User
Apr 5, 2006
31
0
0
US
I have a cells that have a combination of letters like "EGM". I have been trying to make and If/Then that if the cell contains an "E", then I will ask it to copy and paste some cells. So far all I have is:

If Sheet1.Range("b12:b12") = "=E" Then
GoTo line1
Else GoTo line2
line1:
Sheet1.Range("S16: S16 ").Copy
Sheet1.Range("T16:T16").PasteSpecial

line2:
End If
End sub
If I change the ="=E" to ="EGM", then it works but it has to match all the letters. I want to be able to pick out each letter seperately.

 
Hi,

take a look at the Instr function:

i.e. Instr(1,Cell.Value, "E")

Another thing. I'd avoid the use of the GoTo. It is entirely not necessary:

If Instr(1,Cell.Value, "E") > 0 then
With Sheet1
.Range("S16: S16 ").Copy
.Range("T16:T16").PasteSpecial
End With
End If

Cheers,

Roel
 
And what about the Like operator ?
If Sheet1.Range("B12").Value Like "*E*" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Rofeu,
I gave yours a try but it error out on the
If Instr(1,Cell.Value, "E") > 0 then Not sure what has happened.

However PH, You have done it again. Your code works just fine. You helped me once before and again you are here. Do you have any recommendations of a book or something in order for me to better learn this stuff. I saw this one place: that offered a pretty interesting book. If you have a second to look, perhaps you can advise me. Thanks Again PH
Everyone on this site is so generous with their time and expertise. I know that I am not the only one who apprecates it. Thanks to you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top