Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VB to delete columns except these...

Hello,

I have an Excel worksheet called "Sheet1" and I am looking for a way to
automatically delete all columns in Sheet1 that are not named "Test1" and
Test2". Can someone assist?
--
AndrewB.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default VB to delete columns except these...

Can you describe what you mean by "columns...not named"? Do you mean
"Defined Names"? Or perhaps header text (in Row 1 I presume)? Or did you use
the word "named" in a general context meaning those text strings as cell
values in some particular (unspecified) column? Or something else entirely?

--
Rick (MVP - Excel)



"AndrewB" wrote in message
...
Hello,

I have an Excel worksheet called "Sheet1" and I am looking for a way to
automatically delete all columns in Sheet1 that are not named "Test1" and
Test2". Can someone assist?
--
AndrewB.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default VB to delete columns except these...

sub deletecolumns()
dim i as long
for i=cells(1,columns.count).end(xltoleft).column to 1 step -1
if cells(1,i)<"Test1" and cells(1,i)<"Test2" then columns(i).delete
next i
end sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"AndrewB" wrote in message
...
Hello,

I have an Excel worksheet called "Sheet1" and I am looking for a way to
automatically delete all columns in Sheet1 that are not named "Test1" and
Test2". Can someone assist?
--
AndrewB.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default VB to delete columns except these...

On May 4, 3:20*am, "Don Guillett" wrote:
sub deletecolumns()
dim i as long
*for i=cells(1,columns.count).end(xltoleft).column to 1 step -1
* *if cells(1,i)<"Test1" and cells(1,i)<"Test2" then columns(i).delete
*next i
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"AndrewB" wrote in message

...



Hello,


I have an Excel worksheet called "Sheet1" and I am looking for a way to
automatically delete all columns in Sheet1 that are not named "Test1" and
Test2". *Can someone assist?
--
AndrewB.- Hide quoted text -


- Show quoted text -


Don's code suits fine then you can consider following smart code for
speed:

Only I have assumed one thing that your first row does not contain any
error value

With Cells.Rows(1)
.Replace what:="Test*", replacement:="=+na()"
.SpecialCells(xlCellTypeFormulas, xlErrors).EntireColumn.Delete
End With


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
Delete & Merge Columns,Delete Rows with filter, etc traderindia Excel Programming 1 July 16th 09 08:17 PM
create a macro to delete columns and then border remaining columns Jane777 Excel Programming 1 July 18th 07 12:08 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
can't delete columns Ed White Excel Programming 6 March 8th 06 03:02 PM
Delete Columns Jean[_5_] Excel Programming 1 March 5th 04 02:03 PM


All times are GMT +1. The time now is 06:34 PM.

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

About Us

"It's about Microsoft Excel"