Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Craig,
When you delete a row, the row numbers of items below all change, so the "Last Row" keeps changing. Starting from the bottom up overcomes this.The following uses the Column of the Activecell to determine the last occupied cell and works from there up. Note that there is no need to Select or Activate. Sub DelRows() Dim LastRow, Rw, Col Col = ActiveCell.Column LastRow = Cells(Rows.Count, Col).End(xlUp).Row For Rw = LastRow To 1 Step -1 If Cells(Rw, Col) = "" Then Rows(Rw).Delete End If Next End Sub Depending on your circumstances, it may be prudent to specify the column directly rather than rely on the selected cell. e.g. Col = 4 Results could be wierd if a cell in the wrong column was selected regards, Don "Craig" wrote in message ... I'm using Excel XP. I can't seem to get the following code to work. The following code deletes any blank row, and then moves to the next row and checks if it's blank, too. If it is, the row is deleted. If not, the row is skipped, etc. The problem I run into is that after the text that I want has had all the blank rows removed, the code will continue executing indefinitely. I need the code to STOP after it has completed deleting the blank rows from my block of text. What I'm trying to do below is set a counter ('y') so that if 25 consecutive rows are blank, then the code will know that the end of the text has come and it's time to end the macro. But the line "y = y + 1" generates the error "code execution has been interrupted." Any thoughts? Sub DeleteRows() Dim y As Long y = 0 Do While y < 25 If ActiveCell.Value = "" Then Selection.EntireRow.Delete y = y + 1 Else ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate y = 0 End If Loop End Sub Thanks. C. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Cannot seem to Cancel EXCEL App Right Click Event using C# | Excel Programming | |||
Input Box Cancel | Excel Discussion (Misc queries) | |||
Cancel sheet change event | Charts and Charting in Excel | |||
cancel input | Excel Discussion (Misc queries) | |||
Cancel terminate event?? | Excel Programming |