looping code

K

Ksenija

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)
 
M

Mike H

Hi,

What is it you want to loop through? It currently loops through every cell
in the active sheet used range and checks the colour. What do you want it to
do?

Columns(1).Select

The above line is erroneous, it adds nothing to what is going on.



Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top