I want to iterate values within various ranges
For eg: I have total of 720 input values.these values should be taken from an input excel sheet. and then calculate the output using the specified formulae. and then write the results to another sheet.
The input values consist of 2 columns containing 720 values in sheet called INPUT. the other input data is obatained through directly entering data in the textbox in userform
i want output values between different ranges of those 720 values.
In sheet1. i want to calculate the values using formulas from o to 720
In sheet2. i want to calculate the values using formulas from 181 to 720 and then 0 to 180 (the output should be in such a sequence)
In sheet3. i want to calculate the values using formulas from 361 to 720 and then 0 to 360 (the output should be in such a sequence)
In sheet4. i want to calculate the values using formulas from 541 to 720 and then 0 to 540 (the output should be in such a sequence)
.I have got the code for calculating the values from o to 720. but im not able to get the particular loop
Code:
Public Sub end_button_Click()
Unload userform1
End Sub
Public Sub ok_Click()
Dim mr As Variant, m As Variant, m0 As Variant, lam As Variant, a2 As Variant
'to get the input values from the userform
strke = Val(stroke.Text)
d = Val(dia.Text)
conrod_length = Val(l.Text)
cg_conrod = Val(l_dash.Text)
pist_mass = Val(pmass.Text)
conrod_mass = Val(conmass.Text)
crankpin_mass = Val(crank_mass.Text)
mr = (pist_mass * (conrod_length - cg_conrod) / conrod_length) + crankpin_mass
m = (cg_conrod * conrod_mass / conrod_length) + pist_mass
r = strke / 2
lam = r / conrod_length
a1 = 1
a2 = lam + ((1 / 4) * (lam) ^ 3) + ((15 / 128) * (lam) ^ 5)
cr_m1 = Val(crank_mass1)
cr_r1 = Val(crank_rad1)
cw_m1 = Val(counter_mass1)
cw_r1 = Val(counter_rad1)
cr_m2 = Val(crank_mass2)
cr_r2 = Val(crank_rad2)
cw_m2 = Val(counter_mass2)
cw_r2 = Val(counter_rad2)
eqm1 = (cr_m1 * cr_r1) - (cw_m1 * cw_r1)
eqm2 = (cr_m2 * cr_r2) - (cw_m2 * cw_r2)
m0 = (eqm1 + eqm2)
'the loop
Dim k As Variant
For f = 2 To Selection.CurrentRegion.Rows.Count - 1
Set i = Worksheets("input").Cells(f, 1)
Set k = Worksheets("input").Cells(f, 2)
y = rad(i)
p = k * 0.1
Cells(f, 16).Select
Selection.Value = p
a = Area(d)
fz = p * a
Cells(f, 17).Select
Selection.Value = fz
fzm = Forcezm(r, mr, m0, y, m, a1, a2)
Cells(f, 18).Select
Selection.Value = fzm
fym = Forceym(r, mr, mo, y, m)
Cells(f, 19).Select
Selection.Value = fym
vp = vprmf(r, m, y)
Cells(f, 20).Select
Selection.Value = vp
vs = vsrmf(r, m, a2, y)
Cells(f, 21).Select
Selection.Value = vs
trf = vp + vs
Cells(f, 22).Select
Selection.Value = trf
rf = trf - fz
Cells(f, 23).Select
Selection.Value = rf
fn = pistonst(rf, lam, y)
Cells(f, 24).Select
Selection.Value = fn
Next f
End Sub
Function Area(d As Variant) As Variant
pi = 22 / 7
Area = (pi * (d ^ 2)) / 4
End Function
Function Forcezm(r As Variant, mr As Variant, m0 As Variant, y As Variant, m As Variant, a1 As Variant, a2 As Variant) As Variant
pi = 22 / 7
rpm = Val(speed.Text)
Forcezm = r * (((2 * pi * rpm) / 60) ^ 2) * (((mr * m0) * 0.001 * Cos(y)) + (m * 0.001 * a1 * Cos(y)) + (m * 0.001 * a2 * (Cos(2 * y))))
End Function
Function Forceym(r As Variant, mr As Variant, m0 As Variant, y As Variant, m As Variant) As Variant
pi = 22 / 7
rpm = Val(speed.Text)
Forceym = r * (((2 * pi * rpm) / 60) ^ 2) * ((mr + m0) * 0.001 * Sin(y))
End Function
Function rad(i As Variant) As Variant
pi = 22 / 7
rad = (i * pi) / 180
End Function
Function Pre(p As Variant) As Variant
Pre = p * 0.1
End Function
Function vprmf(r As Variant, m As Variant, y As Variant) As Variant
pi = 22 / 7
rpm = Val(speed.Text)
vprmf = r * (((2 * pi * rpm) / 60) ^ 2) * m * 0.001 * Cos(y)
End Function
Function vsrmf(r As Variant, m As Variant, a2 As Variant, y As Variant) As Variant
pi = 22 / 7
rpm = Val(speed.Text)
vsrmf = r * (((2 * pi * rpm) / 60) ^ 2) * m * 0.001 * a2 * (Cos(2 * y))
End Function
Function pistonst(rf As Variant, lam As Variant, y As Variant) As Variant
pistonst = (rf * lam * Sin(y)) / ((1 - (lam * lam) * ((Sin(y)) ^ 2)) ^ 0.5)
End Function