Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Sum values in columns based on values in named range | Excel Worksheet Functions | |||
delete the test values, but do not delete the formulas | Excel Discussion (Misc queries) | |||
Delete columns values inbetween | Excel Discussion (Misc queries) | |||
merge text from 2 columns into 1 then delete the old 2 columns | Excel Worksheet Functions | |||
Excel Compare values in columns & display missing values in a new | Excel Discussion (Misc queries) |