Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

can't compile Sub with Parameters

  Asked By: Kuhaylah    Date: Nov 12    Category: MS Office    Views: 604
  

I have the following Excel Macro:

**************************************************
Function CellColorIndex(InRange As Range, Optional _
OfText As Boolean = False) As Integer
'
' This function returns the ColorIndex value of a the Interior
' (background) of a cell, or, if OfText is true, of the Font in the
cell.
'
Application.Volatile True
If OfText = True Then
CellColorIndex = InRange(1,1).Font.ColorIndex
Else
CellColorIndex = InRange(1,1).Interior.ColorIndex
End If
End Function
***********************************************************
The problem is that i can't compile it, when i try to compile appear
a pop up windows to select a Macro name.

I can't compile or use Sub with parameters in my Excel MAcros.

Could you help me?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Liam Bouchard     Answered On: Nov 12

The function  works fine on my machine (xl2003). Did you put the function in
a module?

 
Answer #2    Answered By: Hababah Younis     Answered On: Nov 12

You've written a function, not a macro; you need to call it from a
macro, or use it as a spreadsheet function  in a cell:

run this macro  to test:
Sub blah()
MsgBox CellColorIndex(Range("A1"))
End Sub

(If you want to step through it, put a breakpoint within the function
at, say, the line 'Application.Volatile True' and run the 'blah'
macro, then press F8 repeatedly to step through the function.)

in the worksheet:
=CellColorIndex(A1)

 
Didn't find what you were looking for? Find more on can't compile Sub with Parameters Or get search suggestion and latest updates.




Tagged: