Consulting

Results 1 to 5 of 5

Thread: Colon as part of string in Userform Label

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    5
    Location

    Colon as part of string in Userform Label

    Hi all,

    This site has been a great resource but, this time around, I was not able to find a solution. On my form, I have I have a label, and I am trying to incorporate a calculation in it. I want it to say "Units: x", where x is a number that is calculated.

    UnitsLabel.Caption = "Units " & CStr(ColNumb * RowNumb)

    But I can only make it work if I take out the colon. What can I do to keep the colon. here is what I've tried.

    UnitsLabel.Caption = "Units: " & CStr(ColNumb * RowNumb)

    And this only returned the label as "Units:" The numbers would disappear. I tried this:

    UnitsLabel.Caption = "Units" & CStr(": ") & CStr(ColNumb * RowNumb)

    I hope I've provided all of the detail. Thank you in advance.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Works here

    Capture.JPG

    I didn't know your ColNumb and RowNum so I just used ActiveCell

    
    Private Sub UserForm_Initialize()
        Me.Label1.Caption = "Units: " & CStr(ActiveCell.Row * ActiveCell.Column)
    End Sub
    
    Do you have any On Error Resume Next statement that might be covering an error?

    Hover mouse over RowNum and Col Num and see what their values are
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    5
    Location
    Paul, thank you for your help. I played around with your file and was able to make it do what I wanted to do, but as soon as I made those very same changes to my file, it still would not work. I actually have a userform that lets the user specify row and columns of a table to be generated. The code actually is ran from a combobox change. It still works on your version when I made those changes, but somehow it does not on mine. I can't figure out what would be making the difference. I'll send you both. For reference, it is on lines 31 and 55 of the "NewGameForm".

    Thank you again for your help thus far.
    Attached Files Attached Files

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I think the Label on the Userform was not wide enough

    It was working, just not displaying

    Make it wider and see


    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    5
    Location
    Wow, Paul. You hit the nail right on the head. I can't believe it was something so simple, but excellent super sleuthing to find that. It now all makes sense to me why that colon did it... it was that last character that broke the camel's back.

    Edit: If there's a way that I can give you positive feedback, I'd love to do so.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •