Results 1 to 5 of 5

Thread: [RESOLVED] [Excel 2003] Validation - Input Message

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    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

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    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
  •  



Click Here to Expand Forum to Full Width