Excel - Delete Every Nth (3rd) column.

I have searched EE without finding any ideas on how to do this.

We need to delete evert Third column, starting with column E.

Any assistance or insight would be greatly appreciated.

Tosagua
TosaguaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
This macro will do what you want:
Sub DeleteNthCol()
'
' Macro1 Macro
'
Dim colIdx As Integer, maxCol As Integer, frequency As Integer

colIdx = 5
frequency = 3
maxCol = 20
While colIdx < maxCol
    Columns(colIdx).EntireColumn.Delete
    colIdx = colIdx + (frequency - 1)
Wend
End Sub

Open in new window


Just change frequency to be the N that you desire, and maxCol to be the last column that you want deleted.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
silemoneCommented:
So you would need a macro that:
You cou
You can make ActiveCell column E byt offersetting (0, 5) if 5 if column E.
then offset (0, 3) and delete.
ProfessorJimJamMicrosoft Excel ExpertCommented:
this one will pop and ask you to select range and then which nth column to delete, then put 3 and then it will do the job.
Book1.xlsm
TosaguaAuthor Commented:
I am sorry about this, but I accepted your solution and awarded the points last week. Unfortunately, I am stuck using Internet Explorer 8, which doesn’t work well on Experts Exchange, while IE 11 continually crashes.

Shaun's solution works well on large spreadsheet with more than 200 columns. But ProfessorsJimJam's solution is ideal for smaller spreadsheets. Both solutions are going into our library.

Thank you for the assistance.

Tosagua
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.