#1   Report Post  
Posted to microsoft.public.excel.programming
EJ EJ is offline
external usenet poster
 
Posts: 20
Default Delete Rows

Sub DeleteRows()
Dim i As Long, LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = LastRow To 1 Step -1
If Cells(i, 6) = 0 Then Rows(i).Delete
Next


End Sub

I would like to get some help with this macro. Currently it is deleting
more rows than I want it to delete. I would like it to

Look at each row in Column A.

If the row in Column A has contents in it than check the same row of Column
F.

If the contents in Column F are equal to or greater than €œ0€ delete the row
and keep deleting the rows below it until Column A has contents in it again.

Repeat for every row in Column A and Column F.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Delete Rows

Sub DeleteRows()
Dim i As Long, LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = LastRow To 1 Step -1
If Cells(i, 1) < ""
If Cells(i, 6) = 0 Then Rows(i).Delete
End If
Next


End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"EJ" wrote:

Sub DeleteRows()
Dim i As Long, LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = LastRow To 1 Step -1
If Cells(i, 6) = 0 Then Rows(i).Delete
Next


End Sub

I would like to get some help with this macro. Currently it is deleting
more rows than I want it to delete. I would like it to

Look at each row in Column A.

If the row in Column A has contents in it than check the same row of Column
F.

If the contents in Column F are equal to or greater than €œ0€ delete the row
and keep deleting the rows below it until Column A has contents in it again.

Repeat for every row in Column A and Column F.

  #3   Report Post  
Posted to microsoft.public.excel.programming
EJ EJ is offline
external usenet poster
 
Posts: 20
Default Delete Rows

When I first ran the macro I got a message that said €œCompile Error: Syntax
Error€ so I added €œThen€ to this line If Cells(i, 1) < "" Then, which made
the macro look like this

Sub DeleteRows()
Dim i As Long, LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = LastRow To 1 Step -1
If Cells(i, 1) < "" Then

If Cells(i, 6) = 0 Then Rows(i).Delete
End If
Next


End Sub


And it worked but not in all cases. For some reason one row with €œ0€ did
not get deleted. And a couple other rows in Columns H:O that should have been
deleted didnt get deleted. Could the code be changed instead so that the
macro

Selects a range that begins in Column A and selects to the right until
Column O is included and selects down a number of rows and stops above the
next row in Column A with contents inside of it. Then it looks in Column F
at the first row in the selected range. If the contents inside Column F are
= 0 then all the rows in the selected range get deleted. If not then the

macro moves to the next range and the pattern continues. What do you think?


"Jacob Skaria" wrote:

Sub DeleteRows()
Dim i As Long, LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = LastRow To 1 Step -1
If Cells(i, 1) < ""
If Cells(i, 6) = 0 Then Rows(i).Delete
End If
Next


End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"EJ" wrote:

Sub DeleteRows()
Dim i As Long, LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = LastRow To 1 Step -1
If Cells(i, 6) = 0 Then Rows(i).Delete
Next


End Sub

I would like to get some help with this macro. Currently it is deleting
more rows than I want it to delete. I would like it to

Look at each row in Column A.

If the row in Column A has contents in it than check the same row of Column
F.

If the contents in Column F are equal to or greater than €œ0€ delete the row
and keep deleting the rows below it until Column A has contents in it again.

Repeat for every row in Column A and Column F.

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
Delete Rows if any cell in Column H is blank but do not Delete Fir manfareed Excel Programming 4 September 28th 07 05:20 PM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Excel Programming 2 August 1st 07 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 06:18 PM.

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"