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):
[TABLE="width: 500"]
<TBODY>[TR]
[TD][/TD]
[TD]Pos1[/TD]
[TD]Pos2[/TD]
[TD]Pos3[/TD]
[TD]Pos4[/TD]
[TD]Pos5[/TD]
[TD]Pos6[/TD]
[TD]Pos7[/TD]
[TD]Pos8[/TD]
[TD]Pos9[/TD]
[TD]Pos10[/TD]
[/TR]
[TR]
[TD]time1[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[TD]6.52[/TD]
[TD]0.00[/TD]
[TD]6.52[/TD]
[TD]0.00[/TD]
[TD]39.70[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]time2[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[TD]3.08[/TD]
[TD]0.00[/TD]
[TD]4.08[/TD]
[TD]0.00[/TD]
[TD]13.60[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]time3[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[TD]0.00[/TD]
[TD]29.97[/TD]
[TD]0.00[/TD]
[TD]28.57[/TD]
[TD]0.00[/TD]
[TD]2.03[/TD]
[TD]7.14[/TD]
[TD]0.00[/TD]
[/TR]
</TBODY>[/TABLE]


Into this table:

[TABLE="width: 500"]
<TBODY>[TR]
[TD][/TD]
[TD]Pos4[/TD]
[TD]Pos6[/TD]
[TD]Pos8[/TD]
[/TR]
[TR]
[TD]Time1[/TD]
[TD]6.52[/TD]
[TD]6.52[/TD]
[TD]39.70[/TD]
[/TR]
[TR]
[TD]Time2[/TD]
[TD]3.08[/TD]
[TD]4.08[/TD]
[TD]13.60[/TD]
[/TR]
[TR]
[TD]Time3[/TD]
[TD]29.97[/TD]
[TD]28.57[/TD]
[TD]2.03[/TD]
[/TR]
</TBODY>[/TABLE]


Thanks for your help,
Eric
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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