ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find a specific string in a cell (https://www.excelbanter.com/excel-programming/371115-find-specific-string-cell.html)

loren.pottinger

Find a specific string in a cell
 
I would like to search all the cells that are not empty in column E for
the words Account and New. If the cell does not have either of those
words in it, I would like to delete that entire row, go to the next
cell in column E and repeat this action until I arrive at an empty
cell.

Please help

LP


Myles[_82_]

Find a specific string in a cell
 

sub n()
dim c as range
set rng = Range("e1",Cells(rows.count,"e").end(xlUp))
for each c in rng
if c.value="Account" or c.value="New" then
c.entirerow.delete
end if
next
end sub


hth
myle

--
Myle
-----------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...fo&userid=2874
View this thread: http://www.excelforum.com/showthread.php?threadid=57418


loren.pottinger

Find a specific string in a cell
 
Hey Myles. Thanks for the reply. I attempted that but it didn't exactly
work. I believe that I am leaving out some pertinent information. The
cells that I searching do not only have the words Account or New in
them. They are a part of a longer string where those words are just the
beginning of that string. For example: AccountSalary, or NewMachine.
What I want to do is delete the rows of associated with any cell in
column E that do not have the words Account or New as a part of the
value in the cell. Thank you for you help.

Myles wrote:
sub n()
dim c as range
set rng = Range("e1",Cells(rows.count,"e").end(xlUp))
for each c in rng
if c.value="Account" or c.value="New" then
c.entirerow.delete
end if
next
end sub


hth
myles


--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=574183



LFCFan[_11_]

Find a specific string in a cell
 

Sub sWords()
Range("E1").Select

Do While Len(ActiveCell.Value) < 0
str1 = InStr(1, ActiveCell.Value, "New")
str2 = InStr(1, ActiveCell.Value, "Account")
If str1 = 1 Or str2 = 1 Then
ActiveCell.Offset(1, 0).Select
Else
Selection.Delete Shift:=xlUp
End If
Loop

End Sub

That should do it.

Cheers
Jo

--
LFCFa
-----------------------------------------------------------------------
LFCFan's Profile: http://www.excelforum.com/member.php...fo&userid=3748
View this thread: http://www.excelforum.com/showthread.php?threadid=57418



All times are GMT +1. The time now is 10:28 AM.

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