Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to delete lines

I need a macro that can go down a spreadsheet and when it finds a certian
word to delete that row and the four rows below the first. Any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to delete lines

Put the two lists one after each other on a new sheet. Then go to worksheet
menu

Data - Advancefilter

Select Unique Values Only and Copy to new range. This will give you unique
values. If you need a macro turn on the macro record while performing
operations.

"Cheffred" wrote:

I need a macro that can go down a spreadsheet and when it finds a certian
word to delete that row and the four rows below the first. Any suggestions?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro to delete lines

The following code should do what you want. Change the lines marked
with <<<< to the appropriate values. WS is the worksheet containing
the data to test. StartRow is the row number of the first data
element. ColLetter is the column letter of the column with the data.
FindWhat is the text to find. CompareMethod indicates whether the text
comparison is case sensitive or case insensitive.

Sub AAA()
Dim LastRow As Long
Dim StartRow As Long
Dim RowNdx As Long
Dim ColLetter As String
Dim WS As Worksheet
Dim FindWhat As String
Dim CompareMethod As VbCompareMethod

Set WS = Worksheets("Sheet1") '<<< CHANGE
StartRow = 1 '<<< CHANGE
ColLetter = "A" '<<< CHANGE
FindWhat = "abc" '<<< CHANGE
CompareMethod = vbBinaryCompare '<<< CHANGE
' vbBinaryCompare for case-sensitive
' vbTextCompare to ignore upper/lower
With WS
LastRow = .Cells(.Rows.Count, ColLetter).End(xlUp).Row
For RowNdx = LastRow To StartRow Step -1
If StrComp(.Cells(RowNdx, ColLetter).Value, _
FindWhat, CompareMethod) = 0 Then
.Rows(RowNdx).Resize(5, 1).EntireRow.Delete
End If
Next RowNdx
End With
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 13 Mar 2009 08:55:01 -0700, Cheffred
wrote:

I need a macro that can go down a spreadsheet and when it finds a certian
word to delete that row and the four rows below the first. Any suggestions?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to delete lines

Thanks, that worked great!

As a variation, how would I put this Concatenate function in instead of
deleting the rows?


Range("A9").Select
Selection.Insert Shift:=xlToRight
ActiveCell.FormulaR1C1 = _
"=CONCATENATE(RC[1],R[1]C[1],R[1]C[2],R[1]C[3],R[1]C[4])"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("B9:J9").Select
Application.CutCopyMode = False
Selection.ClearContents


"Chip Pearson" wrote:

The following code should do what you want. Change the lines marked
with <<<< to the appropriate values. WS is the worksheet containing
the data to test. StartRow is the row number of the first data
element. ColLetter is the column letter of the column with the data.
FindWhat is the text to find. CompareMethod indicates whether the text
comparison is case sensitive or case insensitive.

Sub AAA()
Dim LastRow As Long
Dim StartRow As Long
Dim RowNdx As Long
Dim ColLetter As String
Dim WS As Worksheet
Dim FindWhat As String
Dim CompareMethod As VbCompareMethod

Set WS = Worksheets("Sheet1") '<<< CHANGE
StartRow = 1 '<<< CHANGE
ColLetter = "A" '<<< CHANGE
FindWhat = "abc" '<<< CHANGE
CompareMethod = vbBinaryCompare '<<< CHANGE
' vbBinaryCompare for case-sensitive
' vbTextCompare to ignore upper/lower
With WS
LastRow = .Cells(.Rows.Count, ColLetter).End(xlUp).Row
For RowNdx = LastRow To StartRow Step -1
If StrComp(.Cells(RowNdx, ColLetter).Value, _
FindWhat, CompareMethod) = 0 Then
.Rows(RowNdx).Resize(5, 1).EntireRow.Delete
End If
Next RowNdx
End With
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 13 Mar 2009 08:55:01 -0700, Cheffred
wrote:

I need a macro that can go down a spreadsheet and when it finds a certian
word to delete that row and the four rows below the first. Any suggestions?


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
macro to delete lines based on a value - Repost MarkT Excel Discussion (Misc queries) 2 October 19th 06 03:43 PM
macro to delete lines based on a value MarkT Excel Discussion (Misc queries) 4 October 18th 06 11:49 PM
Macro for Excel to add up items and delete extra lines? Fiero84 Excel Programming 1 October 18th 05 03:01 PM
Delete Non-bolded lines only Annette Excel Programming 2 July 6th 05 08:05 PM
Autofilter & delete lines Craig[_2_] Excel Programming 9 June 16th 05 06:06 PM


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