View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Help with code (delete range)

Hi Mr Tom,

Try something like:

'=============
Public Sub TestDelete()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim iRow As Long

Set WB = ThisWorkbook
Set SH = WB.Sheets("Sheet2") '<<==== CHANGE

With SH
iRow = .Range("C" & .Rows.Count).End(xlUp).Row
Set Rng = .Range("C5:C" & iRow)
End With
On Error Resume Next
Rng.SpecialCells(xlBlanks).Delete shift:=xlUp
On Error GoTo 0
End Sub
'<<=============


---
Regards,
Norman


"mr tom" <mr-tom at mr-tom.co.uk.(donotspam) wrote in message
...
Hi all,

I want a macro to start at a certain point, move down to the end of the
text
and delete the empty space between it and the next populated cells.

Not delete rows, rahter delete cells, shifting up.

I've written:

Sub testdelete()

Range("C5").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Offset(-1, 0).Select
ActiveCell.Offset(0, 6).Select
Selection.Delete Shift:=xlUp
Range("C11").Select
End Sub

This doesn't work because the .select sets up a new selection rather than
manipulating the old one.

I appreciate this is rookie stuff, but I don't write much VBA, so I've
never
got very good at it.

Any ideas gratefully received.

Cheers.