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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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