Help with User Form and Loop

Mopar_Mudder

New Member
Joined
Jan 29, 2013
Messages
8
I have a user form that I use to enter data in a spread sheet, I also have a loop running that is based on values of cells in the sheet. I need to be able to enter data in the form at each step of the "for each" in the loop.

Right now I can enter data in the form once and it uses that data for each step of the loop never stopping to let me enter new data. Normally I can find a similar question somewhere and figure this coding out, but this on has got me stumped.

Sample of what I am doing:


Code:
Private Sub commandbutton1_Click()
For Each fineline In fineline_list
        For Each class In class_list
                ws_item_range.Cells(iRow, 13).Value = cost 'item from user form, need to change for every step
                ws_item_range.Cells(iRow, 14).Value = unit 'item from user form, need to change for every step
       Next class
Next fineline
End Sub
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Can't you use the userform to enter all the data then run the code?
 
Upvote 0
Can't you use the userform to enter all the data then run the code?

The data needs to be changed for each loop.

Their are 44 finelines and 5 classes, so that is 220 steps to the loop. At each step I need to beable to change things on the form
 
Upvote 0
It's not clear what you want to do.

Perhaps you could try showing the userform when it's required in the loop.

If done correctly the loop code should continue when the userform is unloaded.
 
Upvote 0
It's not clear what you want to do.

Perhaps you could try showing the userform when it's required in the loop.

If done correctly the loop code should continue when the userform is unloaded.

Sorry it is hard to explain, and the answer is probably easy, let me try to explain further.

In the sheet the flowing information is permananet.

A2:A45 have a 4 digit number in each one, this is a fineline code for materials.
B1:F1 have a 3 digit number in each one, this is a class for each fine line.

My code needs to fill in the grid B2:F45 with the cost of each fineline/class combination and each cost is different
The form also displays the fineline/class combination so you know which one you are on

So for the first step it would display the value of A2 and B1 and ask for the cost to go into B2
The next step would be display value of A2 and C1 and ask for C2 and so on ---- this is where it goes wrong, I can't get it to stop and ask for C2, it uses the value entered in the first step

Clear as mud right? I can get it to work perfect using a InputBox, but I need more then what just a InputBox can do so I need to use a form
 
Upvote 0
Why do you need a loop?

Just have a button on the form that puts the cost for the current fineline/class combination on the sheet then moves onto the next fineline/class combination.

Or list all the fineline/class combinations in the first 2 columns of a 3 column listbox.

Then the user can select a combination, enter the cost and then click a button to add the cost in the 3rd column.

When they are finished they click another button to put all the values from the listbox on the sheet.
 
Upvote 0
Why do you need a loop?

Just have a button on the form that puts the cost for the current fineline/class combination on the sheet then moves onto the next fineline/class combination.

That is exaclty what I want. Guess I don't know of a way to move onto the next combo with out using a loop
 
Upvote 0
Looks like I have gotten myself around this seperating the code between a module and form instead of doing it all in the form. Had to use global variables also, never used them before so I learned something new.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

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