List the values of a variable as the macro processes through a loop

PepperPots

New Member
Joined
Jun 14, 2018
Messages
12
I have a textbox in a userform that I want to list the value of the variable that is being processed through a loop, each time the value changes.
I do not want to over write the previous value. I can change the textbox to something else if that helps. Any suggestions?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I believe what you need to do is to read the value of the textbox initially into a variable then set/change it during the loop and then in the end, set it back to the old value.

something like this pseudo-code:

Code:
oldValue = frmMyForm.tbxMyTextBox.Text

For i = 1 to N
     frmMyForm.tbxMyTextBox.Text = "Whatever Text #" & i
Next i

frmMyForm.tbxMyTextBox.Text = oldValue
 
Upvote 0
If you want a list of the various values the the argument takes, a ListBox would be the way to go


Code:
Dim someVariable as Variant, i as Long

ListBox1.Clear

For i = 1 to 10
    ' calculate someVariable

    ListBox1.AddItem CStr(someVariable)
Next I
 
Upvote 0
Thank you, I am able to add items to the listbox with just ListBox1.AddItem CStr(someVariable), but is it possible to refresh the listbox contents as the loop runs? I want to use it as a sort of progress indicator.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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