Macro to eliminate columns that fail specific criteria

viralnerd2013

New Member
Joined
Apr 8, 2013
Messages
21
Hello MrExcel users:

I need a macro that will hide or delete all columns in a data set where the variation within that column is less than 20. For example, the macro would turn this dataset (which is in the format I will be using):
Pos1Pos2Pos3Pos4Pos5Pos6Pos7Pos8Pos9Pos10
time10.000.000.006.520.006.520.0039.700.000.00
time20.000.000.003.080.004.080.0013.600.000.00
time30.000.000.0029.970.0028.570.002.037.140.00

<TBODY>
</TBODY>


Into this table:

Pos4Pos6Pos8
Time16.526.5239.70
Time23.084.0813.60
Time329.9728.572.03

<TBODY>
</TBODY>


Thanks for your help,
Eric
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi Eric:

How about:

Code:
Sub KolumnKiller()
Dim NLastColumn As Long, N As Long, rCol As Range
NLastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
For N = NLastColumn To 2 Step -1
    Set rCol = Columns(N)
    If wf.Max(rCol) - wf.Min(rCol) < 20 Then
        rCol.EntireColumn.Delete
    End If
Next N
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,881
Messages
6,133,217
Members
449,789
Latest member
foxsparrow

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