ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change a Variable Name in a For...Loop (https://www.excelbanter.com/excel-programming/410932-change-variable-name-loop.html)

RyanH

Change a Variable Name in a For...Loop
 
Is it possible to change the name of a variable in a For...Loop? I am trying
to avoid using a bunch of If...Then Statements. Below is my attempt at the
for loop and the If...Then Statement I am trying to avoid.

'PAINT MATERIAL COSTS
Dim i as Byte
Dim TotalPaint As Currency
Dim Paint1 As Currency
Dim Paint2 As Currency
Dim Paint3 As Currency
Dim Paint4 As Currency
Dim Paint5 As Currency
Dim Paint6 As Currency

For i = 1 To Val(tbxColorsP) '1 < tbxColorsP < 6
If mpgPaint.Pages(i-1).Visible = True Then
Object.Name("Paint" & i) = FaceSqFt * Val("cboAreaP" & i) / 100 *
Val("tbxColorsP" & i) * PlasticPaint_C
Else
Exit For
End If
Next i

TotalPaint = Paint1 + Paint2 + Paint3 + Paint4 + Paint5 + Paint6

********************
If mpgPaint.Pages(0).Visible = True Then
Paint1 = FaceSqFt * Val(cboAreaP1) / 100 * Val(tbxColorsP1) *
PlasticPaint_C
End If
If mpgPaint.Pages(1).Visible = True Then
Paint2 = FaceSqFt * Val(cboAreaP2) / 100 * Val(tbxColorsP2) *
PlasticPaint_C
End If
If mpgPaint.Pages(2).Visible = True Then
Paint3 = FaceSqFt * Val(cboAreaP3) / 100 * Val(tbxColorsP3) *
PlasticPaint_C
End If
If mpgPaint.Pages(3).Visible = True Then
Paint4 = FaceSqFt * Val(cboAreaP4) / 100 * Val(tbxColorsP4) *
PlasticPaint_C
End If
If mpgPaint.Pages(4).Visible = True Then
Paint5 = FaceSqFt * Val(cboAreaP5) / 100 * Val(tbxColorsP5) *
PlasticPaint_C
End If
If mpgPaint.Pages(5).Visible = True Then
Paint6 = FaceSqFt * Val(cboAreaP6) / 100 * Val(tbxColorsP6) *
PlasticPaint_C
End If

TotalPaint = Paint1 + Paint2 + Paint3 + Paint4 + Paint5 + Paint6

Thanks in Advance
Ryan



All times are GMT +1. The time now is 04:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com