|
-
Sep 2nd, 2008, 05:46 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [Excel 2003] Validation - Input Message
I have a spreadsheet which is creating a template spreadsheet for users to
fill out. On some cells I have data validation to restrict the values to a
specific list of values.
For other cells I have no data validation, but I am trying to set these celsl up
so that the InputMessage comes up when selected in the same way when I
have validation set on a cell.
I am using the following code.
Code:
Public Sub InputMessage(ByRef TheRange As Range, ByVal TextMessage As String, _
Optional ByVal TitleMessage As String = "")
' Sets the InputMessage for a Cell or a Range of Cells.
' note that if there is already a message then this will NOT be overwritten.
If IsNull(TheRange.Validation.InputMessage) Then
With TheRange.Validation
.InputMessage = TextMessage
.InputTitle = TitleMessage
.ShowInput = True
End With
End If
End Sub
However it is falling over at the following line.
Code:
If IsNull(TheRange.Validation.InputMessage) Then
With this message:-
Run Time Error 1004
Application defined or Object defined error
I cannot help thinking I am missing something really obvious, but I cannot
work out what.
Any suggestions
Before anyone suggests it I have looked at Koolsid's Data Validation tutorial.
Signature Under Construction 
-
Sep 2nd, 2008, 07:04 AM
#2
Re: [Excel 2003] Validation - Input Message
are you expecting null values in cells?
or should that be if isempty(..................
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 2nd, 2008, 07:30 AM
#3
Thread Starter
Hyperactive Member
Re: [Excel 2003] Validation - Input Message
Hi westconn1.
What I am trying to do in my code is to check to see if there is already an
InputMessage on the validation for the Cell or range.
I do not want to enter something if there is already a message there.
I had tried
Code:
If TheRange.Validation.InputMessage = "" Then
but received the same error message.
Signature Under Construction 
-
Sep 2nd, 2008, 07:45 AM
#4
Re: [Excel 2003] Validation - Input Message
If TheRange.Validation does not exist, you cannot access to TheRange.Validation.InputMessage.
This is my version:
Code:
Public Function SetInputMessage(aRange As Range, Message As String,
Optional Title As String) As Long
'-- return 0: Validation Existed with InputMessage, not added
'-- return 1: Validation Existed with No InputMessage, add new InputMessage
'-- return 2: New added Validation with new InputMessage
Dim sTest As String
With aRange.Validation
On Error Resume Next
sTest = .InputMessage
If Err <> 0 Then
.Add xlValidateInputOnly
SetInputMessage = 1
End If
On Error GoTo 0
If sTest = "" Then
SetInputMessage = SetInputMessage + 1
If Title <> "" Then .InputTitle = Title
.InputMessage = Message
.ShowInput = True
End If
End With
End Function
-
Sep 2nd, 2008, 08:02 AM
#5
Thread Starter
Hyperactive Member
Re: [Excel 2003] Validation - Input Message
Many thanks anhn,
Just what was needed.
Signature Under Construction 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|