PC Review


Reply
Thread Tools Rate Thread

Delete Columns not containing certain values

 
 
Nate
Guest
Posts: n/a
 
      15th Mar 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      15th Mar 2007
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
>
>

 
Reply With Quote
 
Nate
Guest
Posts: n/a
 
      15th Mar 2007
On Mar 15, 11:12 am, Tom Ogilvy <TomOgi...@discussions.microsoft.com>
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
summing up values in a column based on values in 3 other columns =?Utf-8?B?QXhlbA==?= Microsoft Excel Programming 4 30th Mar 2007 10:40 PM
Delete columns values inbetween =?Utf-8?B?RGltcmk=?= Microsoft Excel Misc 1 13th Sep 2006 10:52 AM
Comparing values in two columns and displaying missing values in n =?Utf-8?B?Y3BldHRh?= Microsoft Excel Programming 1 2nd Apr 2005 06:18 AM
Excel Compare values in columns & display missing values in a new =?Utf-8?B?Y3BldHRh?= Microsoft Excel Misc 1 2nd Apr 2005 05:51 AM
Summing only values in visible columns, not in hidden columns =?Utf-8?B?Qlc=?= Microsoft Excel Misc 1 2nd Nov 2004 06:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.