montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hello.
I am in a real trouble here, I understand basic loop ideas, but to loop the macro I am working now, is a hard concept.
I am using countif and the sorting function, but my array is to big, so let me show you the macros I am repeating now,
and do this more than 2000 times now I understand how important is a loop.
ok, this is what I did so far.
Please give me a hand here. thank you.
I think the macro speak by itself.
I am in a real trouble here, I understand basic loop ideas, but to loop the macro I am working now, is a hard concept.
I am using countif and the sorting function, but my array is to big, so let me show you the macros I am repeating now,
and do this more than 2000 times now I understand how important is a loop.
ok, this is what I did so far.
VBA Code:
Sub KLM()
Range("L2:L54").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=COUNTIF($B$2:$G$2,L2)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = 65535
End With
Selection.FormatConditions(1).StopIfTrue = False
'//////////////////////////////////////////////SORT BY COUNT////////////////////////////////////////////////////////////////////////////////////////
Range("L1:M54").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("M2:M54") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("L1:M54")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Sub NOP()
Range("O2:O54").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=COUNTIF($B$3:$G$3,O2)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = 65535
End With
Selection.FormatConditions(1).StopIfTrue = False
'//////////////////////////////////////////////SORT BY COUNT////////////////////////////////////////////////////////////////////////////////////////
Range("O1:P54").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("P2:P54") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("O1:P54")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Sub QRS()
Range("R2:R54").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=COUNTIF($B$4:$G$4,R2)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = 65535
End With
Selection.FormatConditions(1).StopIfTrue = False
'//////////////////////////////////////////////SORT BY COUNT////////////////////////////////////////////////////////////////////////////////////////
Range("R1:S54").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("S2:S54") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("R1:S54")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Please give me a hand here. thank you.
I think the macro speak by itself.