View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
vivmaha vivmaha is offline
external usenet poster
 
Posts: 42
Default Macro loop problem

'Deletes all rows in the current worksheet in which the value of the 1st
column = 0
'NOTE: assumes that the 1st column is only numerical and has no blanks.
Public Sub RowDeletingMacro()

Dim curRow As Integer 'Which row we're examining
curRow = 1

While Cells(curRow, 1) < "" 'While the current row is
non-blank
If Cells(curRow, 1) = 0 Then 'If this is a row that we wish
to delete:
Rows(curRow).Select 'Select the row
Selection.Delete Shift:=x1Up 'Delete it, and shift all
rows under it up
Else 'If tthis is not a row that we
wish to delete:
curRow = curRow + 1 'Move on to a new row
End If
Wend

End Sub


"Ben" wrote:

Hello, I'm very new to writing macros with the Visual Basic editor, so I was
wondering if someone could help me figure out why nothing happens when I run
the following macro:

Sub RowDeletingMacro()

x = 10

Do While Cells(x, 1).Value < ""
If Cells(x, 1).Value = 0 Then
Cells(x, 1).Rows(x).Select
Selection.Delete Shift:=xlUp
End If
x = x + 1
Loop

End Sub


My goal with this macro is to delete all rows in my worksheet that have "0"
as an entry in the first column, and to skip over all of the rows that do not
have 0 as their first column entry. Any help would be greatly appreciated,
thanks very much,

Ben