Results 1 to 6 of 6

Thread: [RESOLVED] A Value in A Caption when Cell is Null

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    161

    Resolved [RESOLVED] A Value in A Caption when Cell is Null

    I have the following code. Problem is that sometimes Cell C1 is Null. When the Cell is Empty, I want to Disable the command Button and change the Caption to nothing to Resume. How can I do this?

    Code:
    Private Sub UserForm_Initialize()
    Dim strCap As String
    strCap = Sheets("Output").Range("C1").Value & " Statement Resumed."
    CmdRes.Caption = strCap
        
    End Sub

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    161

    Re: A Value in A Caption when Cell is Null

    I've tried the following but seems to be something wrong with the Else If.

    Code:
    Private Sub UserForm_Initialize()
    Dim strCap As String
    If Sheets("Output").Range("C1").Value <> "" Then
    strCap = Sheets("Output").Range("C1").Value & " Statement Resumed."
    CmdRes.Caption = strCap
    CmdRes.Default = True
    Else If
    CmdRes.Caption = Disabled
    CmdRes.Default = False
    End If
    End Sub

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

    Re: A Value in A Caption when Cell is Null

    cmdres.caption = "Disabled"
    or
    cmdres.enabled = false
    depending what you want to achieve
    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    161

    Re: A Value in A Caption when Cell is Null

    I get an expected Expression Compile Error with this.Any Ideas?

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

    Re: A Value in A Caption when Cell is Null

    your else if has no condition, should be Else
    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

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

    Re: A Value in A Caption when Cell is Null

    Code:
    Private Sub UserForm_Initialize()
       Dim strCap As String
    
       strCap = Sheets("Output").Range("C1").Value
       If strCap <> "" Then
          CmdRes.Caption = strCap & " Statement Resumed." 
          CmdRes.Default = True
       Else
          '--CmdRes.Caption = "Disabled"
          '--CmdRes.Default = False
          CmdRes.Enabled = False
       End If
    End Sub
    • 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

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