Home Excel Powerpoint Word Outlook Error Codes

VBA Useful Codes

Welcome to the World of VBA
Home > VBAUsefulCodes

Delete Columns Based on Column Headers


Delete entire column based on column headings/names

Sub delete_column_headers_based_on_column_headers()

For i = 1 To 100

 

    col_names = Array("EMPLOYEEID", "EMPLOYEENAME", "EMPLOYEECOMPANY")

    

    col_name = ThisWorkbook.Sheets("sheet1").Cells(1, i).Value

    If col_name <> "" Then

        If (col_name <> col_names(0) And col_name <> col_names(1) And col_name <> col_names(2)) Then

            ThisWorkbook.Sheets("sheet1").Cells(1, i).EntireColumn.Delete

            i = i - 1

        End If

    End If


Next i

End Sub

Subscribe

Enter your e-mail below and get notified on the latest blog posts.




Tags

VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts


Follow Us