Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Need Excel Macro to Find Specific Text and Characters

Try this version:

Dim theRange As Range, Str As String
Dim lastRow&, firstRow&, x&
Set theRange = ActiveSheet.UsedRange
lastRow = theRange.Cells(theRange.Cells.Count).Row
firstRow = theRange.Cells(1).Row
For x = lastRow To firstRow Step -1
Str$ = Left(Cells(x, 22).Value, 2)
Select Case Str$
Case "EE", "KG", "PK"
Rows(x).Delete
Case Else
'do nothing
End Select
Next
Set theRange = Nothing

Hope this helps,

Hutch

"TechEd" wrote:

Hello,
I have a macro created to delete rows that do not contain certain text in a
specific column. However, it is only picking up the cells with that exact
search string, like "KG". How do I get the macro to recognize the other cells
(e.g. "KG-12, "KG-10, PK-6) ? Seems like I need a wildcard for the characters
after the "KG"...The coding is listed below. Thank you!

Dim theRange As Range
Dim lastRow&, firstRow&, x&
Set theRange = ActiveSheet.UsedRange
lastRow = theRange.Cells(theRange.Cells.Count).Row
firstRow = theRange.Cells(1).Row
For x = lastRow To firstRow Step -1
If Not Cells(x, 22) = "'PK-" And Not Cells(x, 22) = "'KG-" And Not Cells(x,
22) = "'EE-" And Not Cells(x, 22) = "'KG" Then
Rows(x).Delete
End If
Next

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
Find and replace specific characters within a cell based on positi ccgsuper Excel Discussion (Misc queries) 2 January 20th 09 02:34 PM
Macro that returns a specific number of characters from a text str Jurassien Excel Discussion (Misc queries) 2 August 1st 07 11:14 PM
How do I find a specific characters position in a string variable [email protected] Excel Programming 3 March 11th 06 02:26 PM
Text String - Specific Characters Kiser Excel Worksheet Functions 6 February 10th 06 02:43 AM
find cells that contain specific characters mshornet Excel Worksheet Functions 8 November 23rd 05 02:02 PM


All times are GMT +1. The time now is 09:39 AM.

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

About Us

"It's about Microsoft Excel"