Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Deleting lines in a macro

I am completely new to macros so please accept my
apologies if what i am asking is very basic.

I have a spreadsheet full of data (sheet1). I want to
delete all rows in the spreadsheet that do not contain the
word "Total" in column A.

I want to know how to do this if:
i) Any part of the cell contains the word "Total"
ii) The cell only contains the word "Total" (and nothing
else)


Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Deleting lines in a macro

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


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Sean" wrote in message
...
I am completely new to macros so please accept my
apologies if what i am asking is very basic.

I have a spreadsheet full of data (sheet1). I want to
delete all rows in the spreadsheet that do not contain the
word "Total" in column A.

I want to know how to do this if:
i) Any part of the cell contains the word "Total"
ii) The cell only contains the word "Total" (and nothing
else)


Thanks



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
A macro for deleting lines of text melara Excel Worksheet Functions 1 January 4th 10 07:29 AM
Deleting unused lines between used lines? Stevel Setting up and Configuration of Excel 1 November 25th 05 12:58 AM
Deleting Lines in Excel sibadee14 Excel Discussion (Misc queries) 1 November 16th 05 06:56 AM
Deleting lines with no data Paulo Gonçalves Excel Programming 2 December 10th 03 03:53 AM
Deleting lines really deletes lines! Jim[_28_] Excel Programming 1 October 2nd 03 03:32 PM


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