adding a variable to a variable in a loop

gtopmafia

New Member
Joined
Jun 8, 2018
Messages
23
Hi Guys Im trying to make a Loop function for the following I want to make the payPer iterate so payPer1, payPer2 etc.

Any idea how I can do this? cheers.

pmtCount = 0
incremental = 0
x = 1
Do While pmtCount < 20
Cells(Rows.Count, 22).End(xlUp).Offset(0, 0).Select
ActiveCell.Offset(0, incremental).Select
ActiveCell.Value = payPer+(what here)
incremental = incremental + 1
pmtCount = pmtCount + 1
x = x + 1
Loop
 
I read that maybe I should use a dictionary, What I am trying to do is for example


payPer1 = CPS.payPer1.Value
payPer2 = CPS.payPer2.Value
payPer3 = CPS.payPer3.Value
payPer4 = CPS.payPer4.Value



pmtCount = 0
incremental = 0
x = 1


Do While pmtCount < 20
Cells(Rows.Count, 22).End(xlUp).Offset(0, incremental).Value = payPer & x
incremental = incremental + 1
pmtCount = pmtCount + 1
x = x + 1
Loop

so that the payPer will become payPer1 in first loop payPer2 in second loop and so forth right now it takes the value of payPer value = 0 + x (1) giving a value of 1
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Did you look at the link earlier that I referenced thats shows looping through controls?
You may need to do something like that. You may need to play around with it.
Like I said, I am not experienced with doing that sort of thing in Excel. I seldom ever use UserForms (I find them quite cumbersome).

Take a look at this reference here, which shows more details on how to loop through controls on a UserForm:
http://www.ozgrid.com/VBA/control-loop.htm
 
Upvote 0
Did you look at the link earlier that I referenced thats shows looping through controls?
You may need to do something like that. You may need to play around with it.
Like I said, I am not experienced with doing that sort of thing in Excel. I seldom ever use UserForms (I find them quite cumbersome).

Take a look at this reference here, which shows more details on how to loop through controls on a UserForm:
http://www.ozgrid.com/VBA/control-loop.htm


Yea I am the same just the userinput box was not a very useful way to get the input data as I need around 20-40 entries at once :( Ill have a look cheers
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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