Help with code (delete range)
Thanks for all the replies.
All I need to do is make the following code work:
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, 11).Select
Selection.Delete Shift:=xlUp
End Sub
C5.Select is the start of the first range of data
The xldown takes me to the end of the range
The offset 1,0 takes me to the first blank cell at the bottom of the range
So far so good.
Range(Selection, Selection.End(xlDown)).Select takes me to the end of the
empty cells, selecting as it goes, but also selects the first cell of the
range of text below
So to try to counter that, I have used
ActiveCell.Offset(-1, 0).Select
But this doesn't work - it selects the top set of text, i.e.
a
b
c
d
e
f
g
_
_
_
_
_
h
i
j
k
l
I need to select all the _ (space) but the offset -1 selects 'g'
I then need to expand that selection to the right by 11 cells, to create a
range which is 11 cells wide and the number of empty cells deep.
I know how to subsequently delete them.
What am I doing wrong?
Cheers,
"mr tom" wrote:
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.
|