Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Delete Columns not containing certain values

Hello,

I'm having trouble writing a VBA macro that deletes columns. I have a
spreadsheet with a bunch of columns containing various data.

What I want to do is delete every column that doesn't have either
"NO.", "QTY." or "DESCRIPTION" in it. I have about 1000 sheets that I
need to clean up and a macro would make this much easier on me.

I already have a macro which deletes the rows I don't need, now I'd
like to add code to delete the columns.

Any suggestions?

Thanks in advance,

-Nate

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Delete Columns not containing certain values

Dim i as Long, cnt as Long, rng as Range
Dim icol as Long
set rng = Activesheet.UsedRange.Rows(1).Cells
icol = rng(rng.count).column
for i = icol to 1 step -1
cnt = Application.countif(columns(i),"*NO.*") + _
Application.countif(columns(i),"*QTY.*") + _
Application.countif(columns(i),"*DESCRIPTION*")
if cnt = 0 then
columns(i).Delete
end if
Next i

--
Regards,
Tom Ogilvy


"Nate" wrote:

Hello,

I'm having trouble writing a VBA macro that deletes columns. I have a
spreadsheet with a bunch of columns containing various data.

What I want to do is delete every column that doesn't have either
"NO.", "QTY." or "DESCRIPTION" in it. I have about 1000 sheets that I
need to clean up and a macro would make this much easier on me.

I already have a macro which deletes the rows I don't need, now I'd
like to add code to delete the columns.

Any suggestions?

Thanks in advance,

-Nate


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Delete Columns not containing certain values

On Mar 15, 11:12 am, Tom Ogilvy
wrote:
Dim i as Long, cnt as Long, rng as Range
Dim icol as Long
set rng = Activesheet.UsedRange.Rows(1).Cells
icol = rng(rng.count).column
for i = icol to 1 step -1
cnt = Application.countif(columns(i),"*NO.*") + _
Application.countif(columns(i),"*QTY.*") + _
Application.countif(columns(i),"*DESCRIPTION*")
if cnt = 0 then
columns(i).Delete
end if
Next i

--
Regards,
Tom Ogilvy

"Nate" wrote:
Hello,


I'm having trouble writing a VBA macro that deletes columns. I have a
spreadsheet with a bunch of columns containing various data.


What I want to do is delete every column that doesn't have either
"NO.", "QTY." or "DESCRIPTION" in it. I have about 1000 sheets that I
need to clean up and a macro would make this much easier on me.


I already have a macro which deletes the rows I don't need, now I'd
like to add code to delete the columns.


Any suggestions?


Thanks in advance,


-Nate


THANK YOU!

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
Sum values in columns based on values in named range Mikael Andersson Excel Worksheet Functions 10 November 12th 08 09:37 AM
delete the test values, but do not delete the formulas kathy Excel Discussion (Misc queries) 1 February 21st 07 07:03 PM
Delete columns values inbetween Dimri Excel Discussion (Misc queries) 1 September 13th 06 10:52 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
Excel Compare values in columns & display missing values in a new cpetta Excel Discussion (Misc queries) 1 April 2nd 05 05:51 AM


All times are GMT +1. The time now is 02:59 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"