ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to loop (https://www.excelbanter.com/excel-discussion-misc-queries/151346-how-loop.html)

saman110 via OfficeKB.com

How to loop
 
I have Columns A:G and many cells I want to delete entire Rows if the content
of the cell contaings certain word. So far I got this Macro, but it does not
loop and I have to run it several times to get it right. is there any way I
could run it once?

Note: the code below looks at cell A2:G2 and deletes the whole Row

Sub DeleteColumns()
Dim i As Integer

For i = 256 To 1 Step -1
If Cells(2, i).Text = "Subtotal of High" Or _
Cells(2, i).Text = "Subtotal of Extremely High" Or _
Cells(2, i).Text = "Subtotal of Average" Or _
Cells(2, i).Text = "Subtotal of Below Average" Or _
Cells(2, i).Text = "Subtotal of Above Average" Or _
Cells(2, i).Text = "Grand Total" Then
Cells(2, i).EntireRow.Delete
End If
Next i
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200707/1


Don Guillett

How to loop
 
think about it.
cells(row,column)

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"saman110 via OfficeKB.com" <u35670@uwe wrote in message
news:759e383fb1fa2@uwe...
I have Columns A:G and many cells I want to delete entire Rows if the
content
of the cell contaings certain word. So far I got this Macro, but it does
not
loop and I have to run it several times to get it right. is there any way
I
could run it once?

Note: the code below looks at cell A2:G2 and deletes the whole Row

Sub DeleteColumns()
Dim i As Integer

For i = 256 To 1 Step -1
If Cells(2, i).Text = "Subtotal of High" Or _
Cells(2, i).Text = "Subtotal of Extremely High" Or _
Cells(2, i).Text = "Subtotal of Average" Or _
Cells(2, i).Text = "Subtotal of Below Average" Or _
Cells(2, i).Text = "Subtotal of Above Average" Or _
Cells(2, i).Text = "Grand Total" Then
Cells(2, i).EntireRow.Delete
End If
Next i
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200707/1



saman110 via OfficeKB.com

How to loop
 
Unfortunatly I cant get it right.

I want to run this macro 6 or 7 times, or loop back to second row and delete
those word until there is none.

thx.

Don Guillett wrote:
think about it.
cells(row,column)

I have Columns A:G and many cells I want to delete entire Rows if the
content

[quoted text clipped - 20 lines]
Next i
End Sub


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200707/1


Don Guillett

How to loop
 

Again, think about it. You are looking in columns and asking to delete rows.
Exactly what do you want to do?
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"saman110 via OfficeKB.com" <u35670@uwe wrote in message
news:75aa591d86731@uwe...
Unfortunatly I cant get it right.

I want to run this macro 6 or 7 times, or loop back to second row and
delete
those word until there is none.

thx.

Don Guillett wrote:
think about it.
cells(row,column)

I have Columns A:G and many cells I want to delete entire Rows if the
content

[quoted text clipped - 20 lines]
Next i
End Sub


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200707/1



Dave Peterson

How to loop
 
Maybe it's time to restate your requirements--without the code.

Are you looking in A1:G1 for any of those strings and then A2:G2 for any of
those strings, then a3:g3....

Or are you looking through a single column for any of those strings.



"saman110 via OfficeKB.com" wrote:

I have Columns A:G and many cells I want to delete entire Rows if the content
of the cell contaings certain word. So far I got this Macro, but it does not
loop and I have to run it several times to get it right. is there any way I
could run it once?

Note: the code below looks at cell A2:G2 and deletes the whole Row

Sub DeleteColumns()
Dim i As Integer

For i = 256 To 1 Step -1
If Cells(2, i).Text = "Subtotal of High" Or _
Cells(2, i).Text = "Subtotal of Extremely High" Or _
Cells(2, i).Text = "Subtotal of Average" Or _
Cells(2, i).Text = "Subtotal of Below Average" Or _
Cells(2, i).Text = "Subtotal of Above Average" Or _
Cells(2, i).Text = "Grand Total" Then
Cells(2, i).EntireRow.Delete
End If
Next i
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200707/1


--

Dave Peterson


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com