Deleting Columns Via Macro

trainer75

New Member
Joined
Jun 11, 2015
Messages
33
Hi,
Hope someone can assist me, i have am new to the whole macro/formula experience and have spent 5 hours today trying different methods of trying to do this.

I have to run reports every week and need to streamline how long it take me to do, so i want to delete out columns in excel that i do not need, only thing is week by week the number of columns changes so cannot use a fixed formula/macro, so started looking at deleting via certain text in one of the cells, which i done by the following:-
Ctrl F chose find and entered the data, then Find All, Selected Ctrl A to highlight all values with the data required, closed down dialog box and then right click delete entire column, job done :) but when i done this in a macro it deleted the whole sheet.

Hope someone can help me,
Thank you in advance
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi..

You would do something like the following:

Columns("F:N").Select
Selection.Delete Shift:=xlToLeft
 
Upvote 0
Thank you for a quick response.

Would i use this in the visual basics part?
its very weird what i am trying to do, i need the info from columns A,B,C,D then there is 2 more columns that this week will be in AM & AN but next week might be in BA & BB.

does that make sense?
 
Upvote 0
there are 4 criteria
Adj Qty
Adj Crac
Gross Qty
Gross Value

these are a constant on every report and the ones i want to delete out :)
 
Upvote 0
Hi Steve,
yes these are the headers
and in row 1 as i have another macro running to sort it to be in row 1
 
Upvote 0
Try this on a COPY of your book:

Code:
Sub DeleteHeaders()

lastCol = Cells(1, Columns.Count).End(xlToLeft).Column

For i = lastCol To 1 Step -1

Select Case Cells(1, i).Value
Case "Adj Qty", "Adj Crac", "Gross Qty", "Gross Value"
Columns(i).Delete shift:=xlToLeft
End Select

Next

End Sub
 
Upvote 0
Hi Steve,

Thank you for this :)

It has worked apart from deleting out the Gross Value columns, will i need to adjust the column (i) to another value?

Your assistance is greatly appreciated :)
 
Upvote 0
It didn't delete them? Click the cell that didn't delete. Does it have a space after the word?
 
Upvote 0

Forum statistics

Threads
1,215,386
Messages
6,124,628
Members
449,176
Latest member
Dazjlbb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top