View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Green[_3_] John Green[_3_] is offline
external usenet poster
 
Posts: 49
Default vba code problem

Remove the parentheses that are around the argument list in the call to the subs.

Sub alterSheet()
Hide_Cells Range("C22:L28")
End Sub

Sub alterSheet2()
Reveal_Cells 3, Range("C21:L28")
End Sub

This is a potentially confusing topic, but you only use parentheses around an argument list when the procedure returns a value that
is being captured (or you use Call).

--

John Green - Excel MVP
Sydney
Australia


"Steve" wrote in message ...
I have written the code below to switch on and off a
coloured input range. The code worked fine in its raw
form but as I try to make it more concise I have
encountered problems, such as VBA suggesting there should
be an '=' after my call to Reveal_Cells

Have I misunderstood the nature of subroutines??

Steve


Sub alterSheet()
Hide_Cells (Range("C22:L28"))
End Sub

Sub alterSheet2()
Reveal_Cells (3,Range("C21:L28")) 'wants = here??
End Sub


Private Sub Hide_Cells(Rng As Range)
Dim c As Range

For Each c In Rng.Cells
c.Interior.ColorIndex = 2
c.Font.ColorIndex = 2
c.Value = 0
Next c

End Sub

Private Sub Reveal_Cells(Default_Value As Variant, Rng As
Range)
Dim c As Range

For Each c In Rng.Cells
c.Interior.ColorIndex = 19
c.Font.ColorIndex = 5
c.Value = Default_Value
Next c

End Sub