PDA

View Full Version : [SOLVED] Colon as part of string in Userform Label



b4bis91
02-16-2019, 05:41 PM
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.

Paul_Hossler
02-17-2019, 07:49 AM
Works here

23753

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

b4bis91
02-17-2019, 11:07 AM
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.

Paul_Hossler
02-17-2019, 11:56 AM
I think the Label on the Userform was not wide enough

It was working, just not displaying

Make it wider and see


23760

b4bis91
02-17-2019, 12:36 PM
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.