Deleting Columns based on a certain criteria

dcdw51

New Member
Joined
Jul 4, 2014
Messages
4
I am having trouble coming up with an algorithm for deleting columns, based on a certain set of criteria. Heres the issue, all the columns have a "1" the top of column . If that column has a cell number that's greater than or equal to 0.90 or less than or equal to -0.90 then that column gets deleted, if it just has a "1" then the row doesn't get deleted. Very complicated set of criteria.:eek:

Thank you
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I am having trouble coming up with an algorithm for deleting columns, based on a certain set of criteria. Heres the issue, all the columns have a "1" the top of column . If that column has a cell number that's greater than or equal to 0.90 or less than or equal to -0.90 then that column gets deleted, if it just has a "1" then the row doesn't get deleted. Very complicated set of criteria.:eek:
But 1 is greater than 0.90 which you say you want deleted?
 
Upvote 0
Let me clarify, all the columns have a "1" cell , so if the cells under the "1" cell have a value greater than 0.90 ( this does include 1) then they get deleted. But if there is just a "1" cell and values less than 0.90 and greater than -0.90, then the row doesnt get deleted.
Heres how the graph looks

1
0.8 1
0.21 0.54 1
0.32 0.22 0.3 1
0.78 0.32 0.92 0.43 1

The third column would get deleted in this case
 
Upvote 0
Let me clarify, all the columns have a "1" cell , so if the cells under the "1" cell have a value greater than 0.90 ( this does include 1) then they get deleted. But if there is just a "1" cell and values less than 0.90 and greater than -0.90, then the row doesnt get deleted.
Heres how the graph looks

1
0.8 1
0.21 0.54 1
0.32 0.22 0.3 1
0.78 0.32 0.92 0.43 1

The third column would get deleted in this case
Okay, to clarify...

When you said in your first message that "all the columns have a '1' the top of column", you did not mean the "1" was in Row 1, correct?

Also, the values being examined are those listed under the "1", correct?

Are all your values constants (that is, not formulas)?

Are all your data columns contiguous?
 
Upvote 0
Yes, Yes, Yes, and all the data in the columns are contiguous. Should of probably put the example in the description.
Thank you
 
Upvote 0
Yes, Yes, Yes, and all the data in the columns are contiguous. Should of probably put the example in the description.
Give this macro a try...
Code:
Sub DeleteColumnsTestCellsBelowTheOne()
  Dim X As Long, Z As Long, LastRow As Long, LastCol As Long, Ones As Range
  Application.ScreenUpdating = False
  LastCol = Cells.Find(What:="*", SearchOrder:=xlByColumns, _
            SearchDirection:=xlPrevious, LookIn:=xlValues).Column
  For X = LastCol To 1 Step -1
    Set Ones = Columns(X).Find(1, Cells(Rows.Count, X), xlValues, xlWhole, , xlNext)
    If Not Ones Is Nothing Then
      LastRow = Cells(Rows.Count, X).End(xlUp).Row
      For Z = Ones.Row + 1 To LastRow
        If Cells(Z, X).Value <= -0.9 Or Cells(Z, X).Value >= 0.9 Then
          Ones.EntireColumn.Delete
          Exit For
        End If
      Next
    End If
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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