Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop with variable name? Mike Excel Discussion (Misc queries) 6 April 25th 09 05:12 AM
LAST value of loop to be a variable Berj Excel Programming 2 December 5th 07 10:19 AM
loop for-next with variable end Valeria Excel Programming 6 November 30th 07 04:14 PM
For Each ... Next loop - need to reference the loop variable [email protected] Excel Programming 4 July 13th 06 06:12 PM
Loop with variable Knut Excel Programming 2 November 19th 05 02:48 PM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"