• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Insert and delete column

Thomas Kuriakose

Active Member
Respected Sirs,

We have a workbook, with the requirement of insertion and deletions of three columns based on a cell value before the cells with headers Total, Max and Min.

The cell B1 = Number of sets of columns to be inserted.

Cells C:E is Group one and on activation of the macro, this should insert a copy of C:E after column E and before the column headers Total, Max and Min based on the input value in cell B1. The formulas in Total, Max and Min should be updated based on the number of sets of columns inserted.

The Group numbers should be incremented based on number of sets inserted as Group1, Group2...

If the number of columns sets to be inserted is less than the existing number of sets, then the corresponding sets of columns should get deleted and the formulas and Group numbers should be adjusted.

I found the below code, but it is inserting only one set at a time and the Groups and Formulas code is not there.
Code:
Sub Insert_Columns()
Dim x As Long
x = Range("B1").Value

Columns("C:E").Select
Selection.Copy
Range(Cells(, 6), Cells(, 6 + x - 1)).Select
Selection.Insert shift:=xlToRight
Application.CutCopyMode = False
Application.EnableEvents = True

End Sub

Kindly guide on how to get this working.

Thank you very much,

with regards,
thomas
 

Attachments

  • Insert Columns.xlsm
    17.5 KB · Views: 3
Respected Sir,

Thank you very much for the code and solution provided for this question.

This works perfectly as per requirement only the Total/max and min should be on the right hand side.

Much appreciated.

Sir, the actual requirement has the Total/Max/Min on the right had side as there are other inputs to be given on the left hand side.

Kindly guide on how to get this on the right hand side.

Thank you very much once again,

with regards,
thomas
 
Thomas Kuriakose ... original snap shot below - okay?
Would You write ... where do other inputs will give?
A-column is already reserved for 'a','b'.
Screen Shot 2017-08-09 at 18.29.22.png
or how many fixed columns (left side from 'a','b') would need those other inputs?
 
Respected Sir,

There are four fixed columns on the left side. Kindly find attached the actual file layout for your reference.

Thank you very much for your support on this,

with regards,
thomas
 

Attachments

  • Insert Columns.xlsm
    18.6 KB · Views: 2
Respected Sir,

Thank you very much for the revised code and solution provided.

Much appreciated.

Sir, is there a possibility to remove the left-option. When I hide the three columns, the right option for Total/max and min does not show.

Kindly help with only the right-option.

Thank you very much,

with regards,
thomas
 
Back
Top