Copy Formulas in New Column

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
Code:
Sub Insert_Column()
Dim ans As Long
ans = InputBox("Insert into Column")
Columns(ans).Insert Shift:=xlToRight
MsgBox "You have Inserted column  " & ans
End Sub
Sub Delete_Column()
Dim ans As Long
ans = InputBox("Delete Column")
Columns(ans).Delete
MsgBox "You have Deleted column  " & ans
End Sub
Can anyone help me to insert or Delete columns after 27th column(AA)
as well as copy the AA column formulas to New columns
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Can i get help with code

I have a 2 command buttons

1. command button= user can give input
suppose user gave no "3" then insert 3 columns after ZZ Column as well as copy from Y5:Y130 and paste it to New inserted Columns.
2. command button= user can give input
suppose user gave no "2" then Delete Entire Column after ZZ (AA,AB)
If User gave less then 3 numbers
Msg box should pop up "Unable to Delete the Source of Data"(Delete only new inserted Columns)
Can macro do it?
 
Upvote 0
Re: Can i get help with code

Inserting and deleting columns is usually a bad thing as all your data moves to a new location. Maybe on insert move all your data "x" number of columns to right. Maybe just clear the contents of the "x" no of columns instead of deleting them. U give an example of using 2 then deleting 2 columns then say that the user can't enter less than 3? HTH. Dave
 
Upvote 0
Re: Can i get help with code

Code:
Sub Insert_Column()
Dim ans As Long
ans = InputBox("Insert into Column")
Columns(ans).Insert Shift:=xlToRight
MsgBox "You have Inserted column  " & ans
End Sub
Sub Delete_Column()
Dim ans As Long
ans = InputBox("Delete Column")
Columns(ans).Delete
MsgBox "You have Deleted column  " & ans
End Sub
This code is for only Deleting and inserting columns
is it possible to add the columns after Z if i click the command Button 1?

I just wanna try this let me see how it will works in my Project
Please help me out with this code
 
Upvote 0
Re: Can i get help with code

@bhandari
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

I have merged the two threads together
 
Last edited:
Upvote 0
Re: Can i get help with code

Usually when U have no replies it is because your question is not clear. U can trial this to get U started. But first place data in "Z" and "AB" then run the code(s). Note how the data in "AB" changes column letter/number. If that's no problem then insert/delete away. Dave
Code:
Sub Insert_Column()
Dim ans As Long
'ans = InputBox("Insert into Column")
colcnt = ActiveSheet.Range("a1:z1").Columns.Count
Columns(colcnt + 1).Insert Shift:=xlToRight
MsgBox "You have Inserted column  " & colcnt + 1
End Sub
Sub Delete_Column()
Dim ans As Long
'ans = InputBox("Delete Column")
colcnt = ActiveSheet.Range("a1:z1").Columns.Count
Columns(colcnt + 1).Delete Shift:=xlToRight
MsgBox "You have Deleted column  " & colcnt + 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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