Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Delete columns of a cell range

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 535
Default Delete columns of a cell range

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Delete columns of a cell range

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

"Jan Karel Pieterse" wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADD A BUTTON TO A CELL TO DELETE A RANGE OF CELLS? traveye Excel Discussion (Misc queries) 5 November 5th 07 12:57 PM
How can I insert and delete rows within a locked cell range column Gordon Cole Excel Worksheet Functions 0 October 1st 06 11:30 AM
merge text from 2 columns into 1 then delete the old 2 columns sleepindogg Excel Worksheet Functions 4 March 30th 06 07:25 PM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
How do you delete one cell from a range of protected cells Cgbilliar Excel Worksheet Functions 2 November 3rd 04 10:42 PM


All times are GMT +1. The time now is 02:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"