Delete columns if all cells have a same criteria in entire cells

uloveonce

New Member
Joined
May 31, 2006
Messages
38
Hello,

I need to delete columns that have "'-" in the entire columns. If I filter that it will only shoe "-" in the drop down. I needed to delete all the columns that have those values in cells. I tried searching but could not come up with any.. There are multiple columns that have these values..

Please assist

Thanks.
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi there,

Assuming the dashes are text not zeros formatted as dashes, try this while on the sheet in question (though initially on a copy of your data as the results cannot be undone if they're not as expected):

Code:
Option Explicit
Sub Macro1()

    Dim lngLastCol As Long
    Dim lngMyCol   As Long
    Dim strMyCol   As String
    
    lngLastCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
    Application.ScreenUpdating = False
    
    For lngMyCol = lngLastCol To 1 Step -1
        strMyCol = Left(Cells(1, lngMyCol).Address(True, False), Application.WorksheetFunction.Search("$", Cells(1, lngMyCol).Address(True, False)) - 1)
        If Evaluate("CountIf(" & strMyCol & ":" & strMyCol & ",""-"")") >= 1 Then
            Columns(strMyCol).EntireColumn.Delete
        End If
    Next lngMyCol
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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