Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding & deleting cells that do not contain a certain text string


Hello,

I'm brand new to VB for Excel, but I am trying...

I have a sheet with multiple columns of data. In column A, I have some
names that have the format "lastname, first initial". Some cells within
column A do not have the comma, and these are the ones that I would like
to delete. I only want to delete the cell (and shift others up), so
that the other columns are not affected.

I found some older posts that had asked a similar problem, but they
dealt with deleting the entire row. When I would change this to just
the selection, the macro would get hung up on that line. Any help
would be greatly appreciated.

Thanks,
Kez


--
clmarquez
------------------------------------------------------------------------
clmarquez's Profile: http://www.excelforum.com/member.php...o&userid=29386
View this thread: http://www.excelforum.com/showthread...hreadid=490983

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Finding & deleting cells that do not contain a certain text string

Sub Test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "A").Value Like "*,*" Then
Cells(i, "A").Delete Shift:=xlUp
End If
Next i

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"clmarquez" wrote
in message ...

Hello,

I'm brand new to VB for Excel, but I am trying...

I have a sheet with multiple columns of data. In column A, I have some
names that have the format "lastname, first initial". Some cells within
column A do not have the comma, and these are the ones that I would like
to delete. I only want to delete the cell (and shift others up), so
that the other columns are not affected.

I found some older posts that had asked a similar problem, but they
dealt with deleting the entire row. When I would change this to just
the selection, the macro would get hung up on that line. Any help
would be greatly appreciated.

Thanks,
Kez


--
clmarquez
------------------------------------------------------------------------
clmarquez's Profile:

http://www.excelforum.com/member.php...o&userid=29386
View this thread: http://www.excelforum.com/showthread...hreadid=490983



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding & deleting cells that do not contain a certain text string


Worked good, except it was deleting the cells that I wanted to keep!
So, I added a "Not" after your "If", and it solved the problem.

Thanks again for the quick reply and solution

--
clmarque
-----------------------------------------------------------------------
clmarquez's Profile: http://www.excelforum.com/member.php...fo&userid=2938
View this thread: http://www.excelforum.com/showthread.php?threadid=49098

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding a charcter in a text string caldog Excel Worksheet Functions 3 October 7th 07 04:37 AM
Finding specific text in a string Hardip Excel Worksheet Functions 5 April 8th 06 01:16 PM
Finding a text string w/in a Cell ricxl Excel Discussion (Misc queries) 12 March 20th 06 03:47 AM
Finding text in a string Paulc Excel Programming 1 December 16th 04 11:55 AM
Finding & Deleting Spaces from Cells sudhendra Excel Programming 2 January 28th 04 12:53 PM


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"