Help with deleting columns based on conditional formatting please

karenhn

New Member
Joined
Nov 30, 2016
Messages
2
I have a spreadsheet with 72 rows and about 10,000 columns. I have applied conditional formatting to highlight all the cells which have a value of less than 150. Is there a way of now deleting all the columns where ALL the cells are highlighted/less than 150? At the moment I have the cells filled in red to make it easier to see the columns with white cells that I want to keep, but I don't want to manually go through all the columns!

Thanks.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi karenhn,

Welcome to MrExcel!!

Try this (initially on a copy of your data as the results cannot be undone if they're not as expected) which doesn't use conditional formatting but simply checks the maximum value in each column before deleting it if this value is less then 150:

Code:
Option Explicit
Sub Macro1()

    'http://www.mrexcel.com/forum/excel-questions/978710-help-deleting-columns-based-conditional-formatting-please.html

    Dim lngLastCol As Long
    Dim lngMyCol   As Long
    Dim lngLastRow As Long
    Dim strMyCol   As String
    
    Application.ScreenUpdating = False

    lngLastCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
    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)
        lngLastRow = Cells(Rows.Count, strMyCol).End(xlUp).Row
        If Evaluate("MAX(" & strMyCol & "1:" & strMyCol & lngLastRow & ")") < 150 Then
            Columns(strMyCol).EntireColumn.Delete
        End If
    Next lngMyCol
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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