View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
The danish student The danish student is offline
external usenet poster
 
Posts: 7
Default Finding max and min across multiple sheets

I have a rather large data set of monthly stock prices for 349 Danish
companies. So the data set is in two sheets due to the limits of 256 columns.
The data set starts in cell "B8" and goes until "FZ8" in both sheets and
continues until row 414
I need a code which sums 3 months return across all companies starting with
"B8" + "B9" + "B10" till "FZ8" + "FZ9" + "FZ10" and afterwards illustrates
the ten largest and smallest 3 month returns across the two sheets by marking
the final cell for example "B10". (optimally it would store the name of the
companies with the relevant month in another sheet)
I need to incorporate a loop as well so the above mentioned macro continues
with summing and illustrating the ten largest and smallest three month
returns. "B9"+"B10"+"B11" all the way to "B412"+"B413"+"B414"

Untill now i have created the following code but there are three problems:
- I do not know how to incorporate the sum macro with the "application.large"
- The loop doesn't work
- The code only works in the active sheet - It cannot look across the two
sheets!

Here is the code:

Public Sub ProcessAllWorksheets()
Dim arr As Variant
Dim answer As Double
Dim totalAnswer As Double
Dim rng As Range, rng1 As Range
Dim l As Double, s As Double
Dim cell As Range

arr = Array("MAK", "MKW")
Sheets(arr).Select

For j = 1 To 9
Set rng = Range("B10").Resize(j, 181)
rng.Interior.ColorIndex = xlNone
l = Application.Large(rng, 10)
s = Application.Small(rng, 10)

For Each cell In rng
If IsNumeric(cell) And _
Not IsEmpty(cell) And cell.Text < "" Then
If cell.Value = l Then
cell.Interior.ColorIndex = 5
ElseIf cell.Value <= s Then
cell.Interior.ColorIndex = 3
End If
End If
Next
Next j
End Sub