Consulting

Results 1 to 4 of 4

Thread: Solved: Code works without proper Dims, why?

  1. #1
    VBAX Tutor
    Joined
    Mar 2009
    Posts
    227
    Location

    Solved: Code works without proper Dims, why?

    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

    [VBA]
    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

    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Unless you have OPtion Explicit at the head of the module, it won't complain.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Tutor
    Joined
    Mar 2009
    Posts
    227
    Location
    Right, I see, so thats how it works out for this code.
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •