PDA

View Full Version : Solved: Code works without proper Dims, why?



Anomandaris
05-21-2009, 07:48 AM
Hi, I've got this code to work, but not sure why its working without proper #Dim variables

i shouldnt be complaining but just curious


Sub mappo()
Dim tcell As Range
Dim Rzsco As Range
Dim PosDec 'why does this work? shouldnt I set it as range or somthing?
Dim NegDec
Dim tMin
Dim tMax

Set Rzsco = Sheets("HeatMap").Range("C7:J7, C10:J10, C13:J13, C16:J16, C19:J19, C22:J22, C25:J25, C28:J28")
With Application.WorksheetFunction
tMax = .Max(0, .Max(Rzsco))
tMin = .Min(0, .Min(Rzsco))
End With
MsgBox "Largest number is: " & tMax & vbCr & "Smallest number is: " & tMin
PosDec = tMax / 6
NegDec = tMin / 6
For Each tcell In Rzsco
Select Case tcell.Value

Case 0 To PosDec
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 36
Case PosDec To (PosDec * 2)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 6
Case (PosDec * 2) To (PosDec * 3)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 44
Case (PosDec * 3) To (PosDec * 4)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 45
Case (PosDec * 4) To (PosDec * 5)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 46
Case (PosDec * 5) To tMax
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 3
Case NegDec To 0
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 24
Case (NegDec * 2) To NegDec
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 17
Case (NegDec * 3) To (NegDec * 2)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 41
Case (NegDec * 4) To (NegDec * 3)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 23
Case (NegDec * 5) To (NegDec * 4)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 5
Case tMin To (NegDec * 5)
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 55
Case Else
tcell.Offset(-2).Resize(3).Interior.ColorIndex = 19
End Select
Rzsco.Font.Bold = True
Next tcell


End Sub

Bob Phillips
05-21-2009, 08:18 AM
Unless you have OPtion Explicit at the head of the module, it won't complain.

mdmackillop
05-21-2009, 09:15 AM
If you don't state a type, the variable will be of type Variant, which could be assigned a number, as your example, or a range, or any other type.

Anomandaris
05-22-2009, 03:29 AM
Right, I see, so thats how it works out for this code.
thanks