Loop an InputBox Until User Selects vbOk

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi, I have a code for the inbox below. The first inbox chooses how many numbers I can sum together, and I want to skip this part, so it just goes to the second inbox. This way I will be able to choose how many digits I want to sum, so I can keep on adding digits until I press "ok", then the textbox, "txtLFWall" will be populated with the result of the sum. By the way, when I press the "ok" there is an error that shows up. Is there anyone that has an idea on how to fix this or how to do it?

Here is the code:
Code:
Private Sub CommandButton11_Click()
Dim TotalNum    As Variant
'Dim TotalNum1     As String
Dim Hits        As Long
Dim SumNums     As Variant
Dim EnteredNum  As Double

'Name = vbNullString
TotalNum = InputBox("How Many Numbers Do You Want to Sum?")
'TotalNum 1 = InputBox("How Many Numbers Do You Want to Sum?")
If TotalNum = "" Then
    Exit Sub
End If

    For i = 1 To TotalNum
        EnteredNum = InputBox("Enter Number Here")   
        SumNums = SumNums + EnteredNum
        Hits = Hits + 1
    Next i
'  If EnteredNum = vbOK Then
 Me.txtLFWall = SumNums
End Sub

Best Regards
 
3. This way I would enter the values in the red textbox and after I press enter key, the red textbox will clear itself and then the value would then go into the green textbox
.

I'm a bit confused.
So you want to transfer the value in the red textbox to the green textbox ONLY after you press enter key? And by the value you mean just the sum of the numbers?
Or you want to transfer the value to the green textbox each time you type a number the red textbox?

Could you explain in more detail what you're trying to do step by step using an example?
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,213,533
Messages
6,114,179
Members
448,554
Latest member
Gleisner2

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