Delete Certain columns based on Values in a Cell

GERALDRAHMAN

New Member
Joined
Apr 11, 2013
Messages
38
Hi All

I would like a Macro that can delete a column if a value in the cell is below a certain criteria, say 10, for example, so all columns that have values in a specific cell address that are <10, will be deleted. The row in which the value resides changes sometimes it's row 11, 12 , 13, up to row 32. I can place a value in a specific cell which excel can use to identify the row number. I have seen a similar question in this forum answered by one of your contributors, but my requirement is somewhat different.

Thanks in advance
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Okay, so I found code that almost does it from within this forum: It follows:

Code:
Sub deleteSpecificTextColumn()    Application.ScreenUpdating = False
    Dim i As Long, LC As Integer, lookFor As String, count As Integer
    
    count = 0
    '16384 is the limit number for Excel 2007, if you're using excel below 2007, replace 16384 with 256
    LC = Cells(1, 16384).End(xlToLeft).Column
    lookFor = InputBox("What text do you want to look for in the first row? (case-sensitive)")
    If lookFor = "" Then
        Exit Sub
    End If
    lookFor = "*" & lookFor & "*"
    
    For i = LC To 1 Step -1
        If Cells(1, i).Value Like lookFor Then
            count = count + 1
            Columns(i).EntireColumn.Delete
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "Done! Found " & count & "."
End Sub

So if I want macro to look at value in row 1 I leave it as it is if I want row 2 then I change -- If Cells(1, i) -- The 1 in the brackets to a 2 etc, but how can I get it to choose the row based on a value in a cell address.
 
Upvote 0

Forum statistics

Threads
1,203,485
Messages
6,055,686
Members
444,807
Latest member
RustyExcel

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