-1

Through VBA - How to find a specific column by name say Inception_Month and if found delete entire column and if not found, go ahead with the remaining code. Please help guys.

I already tried this by recording a macro by doing Ctrl F but it gives error if it doesn't find a particular column name, I don't want to see the error. I want the code to continue with next steps if no column exists by name "Inception_Month".

If Column name is found - I want the entire column to be removed and right next column to be moved at the deleted column space, don't want to see an empty column.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 1
    Please post the code that you have tried. Then go to https://stackoverflow.com/questions/37686841/find-column-header-by-name-and-select-all-data-below-column-header-excel-vba and look at the second solution (or google >vba excel find column name<) – donPablo Apr 22 '19 at 00:19

1 Answers1

0

You can go to insert make it a table and then you can use something like the below.

MyTableName.HeaderRowRange.Cells.Find("Inception_Month").Delete

Or use something like below

Sub Find_Column()
Dim ws as ActiveSheet

Set ws = ActiveSheet
With ws
    Set c = .Find("Inception_Month", LookIn:=xlValues)

    If Not c Is Nothing Then
        ' some code here
    else
        Columns(c.Column).Delete
    End If
End With
End Sub
QuickSilver
  • 730
  • 5
  • 28