• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Error while referencing Range(RangeName) as passed parameter

inddon

Member
Hello There,

I have a sub which check if the value entered is Numeric. I am passing the cell's range as a parameter. Could you please advise and correct


It errors out in Function IsValueNumeric

Rumtime error '1004':
Method 'Range'of object _Global failed


Code:
  Range(pRange).Interior.ColorIndex = 0

  and

  Range(pRange).Interior.ColorIndex = 6 'Highlight with Yellow Color


The code:

Code:
Sub DataValidate()
  Dim Output As Boolean
  If Not IsValueNumeric(Range("FIsNumeric")) Then
    MsgBox ("Value is not Numeric")
  End If
End Sub



Code:
Public Function IsValueNumeric(pRange As Range) As Boolean
  If IsEmpty(pRange.Value) Or _
     Len(pRange.Value) <> 7 Or _
     IsNumeric(pRange.Value) <> True Then
     GoTo Exception_IsValueNumeric
  End If

Done:
  IsValueNumeric = True
  Range(pRange).Interior.ColorIndex = 0
Exit Function

Exception_IsValueNumeric:
  Range(pRange).Interior.ColorIndex = 6 'Highlight with Yellow Color
  MsgBox "- Employee Number has to be Numeric, not empty and of Length 7"
  IsValueNumeric = False
End Function


Thanks & regards,
Don
 
The problem is resolved with:

pRange.Interior.ColorIndex

Regards,
Don
 
Last edited by a moderator:
Back
Top