Userform help

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
140
Office Version
  1. 365
  2. 2019
This is my first attempt at building a Userform. It was actually going well and everything was working until I realized that one of my boxes was not posting a result. On the form I have a series of questions with Points awarded based on the answer. For example: It the answer to question 1 is worth 10 points the person will click on a OptionButton for 10 points and 10 will show in a TextBox next to it. This works all the way down the sheet for 13 questions but I couldn't get the boxes to add and populate in a TextBox named Your Total Points. Then it occurred to me that this is because they are all text boxes. I have tried variety of things to get it to add but the best I could get was if Q1 was 10 and Q2 was 5 Your Points were 105.

I did find a thread on here were someone had a similar problem but solved it themselves so I never really got to see what it was that they solved.

How do I get the each text boxes to display results as numeric? Any help would be greatly appreciated.

Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try something like
Code:
Clng(Textbox1.value) + Clng(textbox2.value)
 
Upvote 0
TextBoxes contain text, not numbers. To be able to add the numbers in them, try wrapping the textbox value in a Val function call inside of your adding code.
 
Upvote 0
where would I put the Clng? would that go in the UserForm code or in the Sub for the actual text box? here is what I had last. I would set the CSRPoints.Value to 0 but in text

Private Sub Points1_Change()
CSRPoints.Value = 0 + Points1.Value
End Sub
 
Upvote 0
Maybe this: ?

When TB13 is changed, it will check to see that all TBs are filled, and if so will total them into TbYourTotal

Code:
Private Sub TextBox13_Change()
Dim i As Long
Dim j As Long
Dim ttl As Double

    For i = 1 To 13
        If Me.Controls("Textbox" & i).Value = "" Then
            MsgBox "Please select a point value for question " & i
        End If
    Next i

    For j = 1 To 13
        ttl = ttl + Me.Controls("Textbox" & j).Value
    Next j
    
    Me.TbYourTotal.Value = ttl
    
End Sub
 
Upvote 0
using the above didn't change anything I am getting 105105510101055 in my total box.

I did use the Clng(Textbox1.value) + Clng(textbox2.value) and it works fine as long as I don't string more than four of them together.
 
Upvote 0
Try Rick's suggestion of using Val rather than Clng
 
Upvote 0
using the above didn't change anything I am getting 105105510101055 in my total box.

I did use the Clng(Textbox1.value) + Clng(textbox2.value) and it works fine as long as I don't string more than four of them together.

That's odd. I made a UF, with 13 TBs with default names (Textbox1, 2, 3, etc) and a TB named like above, and put 1, 2, 3, 4......13 in the textboxes, and it put 91 in the total TB.
 
Upvote 0
@jproffer
Whilst your code works, if the OP didn't declare ttl then you'll get a string result.
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top