Deleting Columns

Deleting Columns


Basic Usage

[sourcecode language=”vb” light=”true” wraplines=”false” gutter=”false”]
Columns("A:A").EntireColumn.Delete
[/sourcecode]


Delete columns based on cell value

Use this code to remove a column based on the cells in row 1 of the column to be deleted. In this case, if there is “Bldr Rebate” in AJ1 then the entire column will be deleted, likewise if there is “Cost Rebate” in column AI1 then that column will be deleted.
[sourcecode language=”vb” light=”true” wraplines=”false” gutter=”false”]
Sub RemoveColumns()

‘Remove Extraneous Columns
If Cells(1, 36) = "Bldr Rebate" Then
Columns("AJ:AJ").EntireColumn.Delete
End If
If Cells(1, 35) = "Cost Rebate" Then
Columns("AI:AI").EntireColumn.Delete
End If

End Sub
[/sourcecode]