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
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows
What cell will you be putting the column number into?
 

isaackoh8393

New Member
Joined
Mar 7, 2014
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

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
 

muan19

New Member
Joined
Jun 27, 2015
Messages
4
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.
 

muan19

New Member
Joined
Jun 27, 2015
Messages
4

ADVERTISEMENT

What cell will you be putting the column number into?

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. If I enter C then column C should be deleted and so on.
 

jorismoerings

Well-known Member
Joined
Jul 4, 2014
Messages
1,284
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!
 

muan19

New Member
Joined
Jun 27, 2015
Messages
4
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:)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,534
Messages
5,596,734
Members
414,093
Latest member
Tegglet

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
Top