A
Abie Giordano
hello everyone
so, i have this code:
Sub GetValue()
Dim rRH, rYear, r1 As Range
Dim RowIndex, ColIndex, yearRow As Integer
Dim rh1 As Integer
Dim rh1Pct As Double
Dim year As String
RowIndex = 30
yearRow = 10
Do While RowIndex < (RowIndex + yearRow)
Set rRH = ThisWorkbook.Sheets("CF-Apar").Range("M" & CStr(RowIndex))
If rRH.Value <> "" Then
rh1 = rRH.Value
year = ThisWorkbook.Sheets("CF-Apar").Range("A" & CStr(RowIndex)).Value
Exit Do
End If
RowIndex = RowIndex + 1
Loop
RowIndex = 12
rh1Pct = Range("D12").Value
ColIndex = 0
Set rYear = Range("D120")
Do While ColIndex < yearRow
If CInt(year) > CInt(rYear.Value) Then
Set r1 = rYear
r1.Offset(123, 0).Value = "0"
End If
If year = rYear.Value Then
rYear.Offset(123, 0).Value = rh1 * rh1Pct
Exit Do
End If
Set rYear = rYear.Next
Set r1 = r1.Next
Loop
End Sub
it was supposed to calculate the value (rh1*rh1Pct)
but how if i want to use range, what should i do?
for example the CF-Apar sheet
M N O P Q
687
412 428
275 490
306 612
367 601
245 1,002
401 1,002
1,002
the value of "687" for example, will be multiplied by D's 85% in Apr-15
C D E F G
Apr-15 85% 8% 5% 2%
May-16 84% 9% 5% 2%
Apr-18 85% 8% 5% 2%
May-19 84% 9% 5% 2%
Oct-21 79% 11% 6% 4%
the current code only calculate the M column, how to make it count N through Q too, so the M's "412" will be calculated with the E's 8% in Apr-15? some of my friend suggested nested looping, but i don't quite understand it, any ideas?
so, i have this code:
Sub GetValue()
Dim rRH, rYear, r1 As Range
Dim RowIndex, ColIndex, yearRow As Integer
Dim rh1 As Integer
Dim rh1Pct As Double
Dim year As String
RowIndex = 30
yearRow = 10
Do While RowIndex < (RowIndex + yearRow)
Set rRH = ThisWorkbook.Sheets("CF-Apar").Range("M" & CStr(RowIndex))
If rRH.Value <> "" Then
rh1 = rRH.Value
year = ThisWorkbook.Sheets("CF-Apar").Range("A" & CStr(RowIndex)).Value
Exit Do
End If
RowIndex = RowIndex + 1
Loop
RowIndex = 12
rh1Pct = Range("D12").Value
ColIndex = 0
Set rYear = Range("D120")
Do While ColIndex < yearRow
If CInt(year) > CInt(rYear.Value) Then
Set r1 = rYear
r1.Offset(123, 0).Value = "0"
End If
If year = rYear.Value Then
rYear.Offset(123, 0).Value = rh1 * rh1Pct
Exit Do
End If
Set rYear = rYear.Next
Set r1 = r1.Next
Loop
End Sub
it was supposed to calculate the value (rh1*rh1Pct)
but how if i want to use range, what should i do?
for example the CF-Apar sheet
M N O P Q
687
412 428
275 490
306 612
367 601
245 1,002
401 1,002
1,002
the value of "687" for example, will be multiplied by D's 85% in Apr-15
C D E F G
Apr-15 85% 8% 5% 2%
May-16 84% 9% 5% 2%
Apr-18 85% 8% 5% 2%
May-19 84% 9% 5% 2%
Oct-21 79% 11% 6% 4%
the current code only calculate the M column, how to make it count N through Q too, so the M's "412" will be calculated with the E's 8% in Apr-15? some of my friend suggested nested looping, but i don't quite understand it, any ideas?