Delete a specific column by using Macro

muan19

New Member
Joined
Jun 27, 2015
Messages
4
Hi,
Please help me to create a button in Excel on which assign a macro with a condition that when I enter column name in cell and press the button then it automatically delete that column.

Thanks in Advance.

Muan
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi,
Please help me to create a button in Excel on which assign a macro with a condition that when I enter column name in cell and press the button then it automatically delete that column.

Thanks in Advance.

Muan

Sub Delete()
Dim delval

del = Range("A1").Value

for i = 2 to 100
if cells(i,1).value = del then
cells(i,1).value.entirerow.delete
endif
next i

end sub
 
Upvote 0
For Example:
I need a button in cell A1 and When I enter D in Cell A2 and press the button then column D should be deleted.
 
Upvote 0
Create the button and asigning the macro is easy to do. The VBA should look like this:

Sub Macro1()
'
Code:
' Macro1


    i = Range("A2").Value
    Range(i & "1").EntireColumn.Delete
   
End Sub

Be aware: when entered column A the macro deletes column A including the button!
 
Upvote 0
create the button and asigning the macro is easy to do. The vba should look like this:

Sub macro1()
'
Code:
' macro1


    i = range("a2").value
    range(i & "1").entirecolumn.delete
   
end sub

be aware: When entered column a the macro deletes column a including the button!

thank you a great help:)
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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