Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default looping code

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

"Ksenija" wrote:

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)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping rather than code for each row Martin Excel Programming 11 September 9th 08 03:10 PM
Code looping through files Otto Moehrbach Excel Programming 66 January 5th 07 07:46 PM
Help with Looping Code JimMay Excel Programming 5 June 6th 06 03:43 AM
Looping macros using VB code accessuser1308 Excel Discussion (Misc queries) 2 March 9th 05 11:11 PM
Code looping when it should not Todd Huttenstine Excel Programming 3 May 13th 04 09:37 PM


All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"