Thread: looping code
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ksenija Ksenija is offline
external usenet poster
 
Posts: 19
Default looping code

hi!

I have this code and I want to have it inside a loop. Am I supposed to
somhow empty MyRange and MyRange1 for every loop??

Sheets("Blad3").Select
Columns(1).Select

Dim MyRange As Range, MyRange1 As Range
Set MyRange = ActiveSheet.UsedRange
For Each c In MyRange
If c.Interior.ColorIndex = 40 Then
If c.Interior.Pattern = xlSolid Then
If MyRange1 Is Nothing Then
Set MyRange1 = c
Else
Set MyRange1 = Union(MyRange1, c)
End If
End If
End If
Next
average_färg = WorksheetFunction.Average(MyRange1)
maxvalue_färg = WorksheetFunction.max(MyRange1)
medianvalue_färg = WorksheetFunction.Median(MyRange1)