Delete columns of a cell range

G

Guest

This has to be dead simple but I can't find the answer in HELP anywhere. In a
macro I have the following code:

Range("last.property").Select
ActiveCell.Offset(0, -1).Select
Range(ActiveCell, "H29").Select
SendKeys "^ " 'selects the columns of the cell range
Selection.Delete Shift:=xlToLeft

What I want to do is delete all the columns from "H" to the one before the
column that has the cell "last.property" in it (its column location is
variable)

The problem is that instead of deleting the columns it deletes only the cell
range, I guess because they are still active. How do I get it to select only
the columns so that they can be deleted?
Thanks and regards, Brett
 
J

Jan Karel Pieterse

Hi Brettjg,
Range("last.property").Select
ActiveCell.Offset(0, -1).Select
Range(ActiveCell, "H29").Select
SendKeys "^ " 'selects the columns of the cell range
Selection.Delete Shift:=xlToLeft

like this:

Range(Range("last.property").Offset(,-1),Range("H29")).EntireColumn.Delet
e


Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com
 
G

Guest

Hi Jan

Thankyou for that (very elegant and brief code). In the interim I had
actually done something very similar, but the Sendkeys command was stuffing
things up - it was always selecting an entire column after it ran. Works
perfectly with your code. Thanks & regards, Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top