Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Removing lines of data that do not contain required data (macro)

I would like to delete rows of data that do NOT contain
the word "Total" in column A.

An earlier response from Rob suggested the following would
work:

Sub test()
Dim rng As Range, i As Long

With ActiveSheet
For i = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
If LCase(.Cells(i, 1).Value) Like "*total*"
Then
If rng Is Nothing Then Set rng = Rows(i)
Else Set rng =
Union(rng, Rows(i))
End If
Next
If Not rng Is Nothing Then rng.Delete xlShiftUp
End With
End Sub


however, this Deletes the rows that contain the
word "Total" and keeps the other non "Total" rows (which
is the opposite of what I want.

Any ideas ?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Removing lines of data that do not contain required data (macro)

Hi
replace the line
If LCase(.Cells(i, 1).Value) Like "*total*" Then

with the following statement:
If InStr(LCase(.Cells(i, 1).Value),"total")=0 Then

--
Regards
Frank Kabel
Frankfurt, Germany

"Sean" schrieb im Newsbeitrag
...
I would like to delete rows of data that do NOT contain
the word "Total" in column A.

An earlier response from Rob suggested the following would
work:

Sub test()
Dim rng As Range, i As Long

With ActiveSheet
For i = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
If LCase(.Cells(i, 1).Value) Like "*total*"
Then
If rng Is Nothing Then Set rng = Rows(i)
Else Set rng =
Union(rng, Rows(i))
End If
Next
If Not rng Is Nothing Then rng.Delete xlShiftUp
End With
End Sub


however, this Deletes the rows that contain the
word "Total" and keeps the other non "Total" rows (which
is the opposite of what I want.

Any ideas ?


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
Removing Data Tables formed from importing data from Access Andrea Jones Excel Discussion (Misc queries) 0 April 10th 08 12:01 PM
Need macro for copying random lines of data FeFi Excel Discussion (Misc queries) 3 March 13th 08 06:47 PM
Help Required!!! Macro to load data from version 1 to version 2 [email protected] Excel Worksheet Functions 0 August 23rd 06 07:27 AM
Macro to copy range of formulas to equal data lines lh Excel Worksheet Functions 2 August 15th 05 04:37 PM
Scanning for Duplicate Data in a Column, Merging Data and Finally Removing All Duplicates...? : VB : Excel Programming 2 August 24th 03 02:22 PM


All times are GMT +1. The time now is 07:31 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"