calcuate formula by loop with vba

nidhipatel

Board Regular
Joined
Feb 11, 2017
Messages
52
my userform contain 3 textbox
TextBox1 value = 1
TextBox2 value = 5
TextBox3 value = 10000
sheet1 range("C2") = 120000
and range C3 formula is = C2*(1+6/100)
now
formula start from range C3
my problem is i need formula calucate till TextBox2 value ie. 5 menas formula calucate 5 cells C3:C7 if i enter value in TextBox 2 = 10 than
formual calcuate "C3:C12"

my result is shown as bleow if i enter Textbox2 Value is 5

<tbody>
[TD="class: xl63, align: right"]120000[/TD]

[TD="class: xl63, align: right"]127200[/TD]

[TD="class: xl63, align: right"]134832[/TD]

[TD="class: xl63, align: right"]142922[/TD]

[TD="class: xl63, align: right"]151497




if i enter TextBox2 value Is 10 than restul shown as

[/TD]

</tbody>

<tbody>
[TD="class: xl65, align: right"]120000[/TD]

[TD="class: xl65, align: right"]127200[/TD]

[TD="class: xl65, align: right"]134832[/TD]

[TD="class: xl65, align: right"]142922[/TD]

[TD="class: xl65, align: right"]151497[/TD]

[TD="class: xl65, align: right"]160587[/TD]

[TD="class: xl65, align: right"]170222[/TD]

[TD="class: xl65, align: right"]180436[/TD]

[TD="class: xl65, align: right"]191262[/TD]

[TD="class: xl65, align: right"]202737[/TD]

</tbody>

it is not done by manually it is done by vba macro only
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
can I just check what the next formula would be to see if i have it right.
 
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
   Range("C3").Resize(Me.TextBox2.Value).Formula = "=c2*(1+6/100)"
End Sub
 
Upvote 0
Or if you don't want the formula
Code:
Private Sub CommandButton1_Click()
   With Range("C3").Resize(Me.TextBox1.Value)
      .Value = Evaluate(Replace("if({1},@*(1+6/100))", "@", .Offset(-1).Address))
   End With
End Sub
 
Upvote 0
Code:
Dim TBox1 As Single
Dim TBox2 As Single
Dim TBox3 As Single
Dim FLoop As Integer




Sub RepeatFormula()
TBox1 = ActiveSheet.TextBox1.Value
TBox2 = ActiveSheet.TextBox2.Value
TBox3 = ActiveSheet.TextBox3.Value


ActiveSheet.Range("C2").Value = 120000
For FLoop = 3 To 3 + TBox2
    ActiveSheet.Range("C" & FLoop).Value = ActiveSheet.Range("C" & FLoop - 1).Value * (1 + 6 / 100)
Next FLoop
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,579
Members
452,653
Latest member
craigje92

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