Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help: search and delete columns

I'm working in a huge excel spreadsheet (AA:EN). I need to delete all
but 15 columns. How can I create a macro which will search for the
column name and then delete that entire column. Also if the column is
not found how can I program the macro to move to the next
search/delete? Anyway help would be greatly appreciated.

So far this is what I have, but I want to delete the columns without
specifying the Column location as these columns could be in different
locations due to formating issues on another spread sheet.

Cells.Find(What:="private label", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False).Activate
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Cells.Find(What:="alternate", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False).Activate
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Range("D12").Select
Cells.Find(What:="purchase", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False).Activate
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Need help: search and delete columns

Dim rng as range

For each rng in Range("A1:EN1")
If rng.value = "alternate" then
rng.entirecolumn.delete
End if
Next rng

This assumes that your column header labels are in A1:EN1.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Need help: search and delete columns

Sorry I didn't see you had three different column headers to be
deleted:

Dim rng as range

For each rng in Range("A1:EN1")
Select case rng.value
case "private label","alternate","purchase"
rng.entirecolumn.delete
End Select
Next rng

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
keyword search and delete row mikeyVo Excel Discussion (Misc queries) 2 August 1st 06 05:32 PM
Search & delete ANY text in select columns huruta Excel Discussion (Misc queries) 2 June 30th 06 07:31 PM
Add-in to search and delete Robert Christie[_3_] Excel Programming 1 October 21st 04 05:49 PM
Search and Delete scottnshelly[_56_] Excel Programming 0 July 4th 04 03:33 AM
Macro to search, compare, copy and delete mark_l_88 Excel Programming 2 April 24th 04 09:08 PM


All times are GMT +1. The time now is 12:09 AM.

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"