View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
David David is offline
external usenet poster
 
Posts: 1,560
Default delete row if no data, non-contiguous range problem

Hi,
It seems you have identified part of the problem yourself. It does not work
on multiple selections. The code you put in does not delete the right row
because i is started at 1 and the row starts at 8:

Range("A8:A58,D8:K58").Select

I think you need to Col A, then D, E F G H I J and K one at a time

Selection.Rows(i).EntireRow.Delete (i is not the ActiveRow, if there is an
activerow)


"Nile Gilmanov" wrote:

Hi my name is Nile.

I have the following code that checks every row from the bottom for any data
and having found none deletes it, then goes on, it is limited to the certain
range.

It works fine with contiguous range such as ("A10:C20"), but does not work
with non-contiguous ranges such as ("A10:C20, E10:G20")... can someone help
me please?

here is the code:
-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-
Dim i As Long

'turn off calculation and screenupdating.
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False

Range("A8:A58,D8:K58").Select

'working backwords because deleting rows.
For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-