Create Variables from other variables

AlanAnderson

Board Regular
Joined
Jun 7, 2010
Messages
134
Hi All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
This may seem silly but I have a blank regarding the logic.<o:p></o:p>
<o:p></o:p>
I need to set up a number of routines that will add totals.<o:p></o:p>
<o:p></o:p>
The actual number can vary. I can establish the number by doing a count (vCount)<o:p></o:p>
<o:p></o:p>
What I need to do, therefore, is have routines that basically say:<o:p></o:p>
Code:
[FONT=Times New Roman][SIZE=3]vStd1 + vDup1 + vTax1 = vTotal1 [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]vStd2 + vDup2 + vTax2 = vTotal2 [/FONT][/SIZE]
<o:p></o:p>
and so on up to figure in vCount<o:p></o:p>
<o:p></o:p>
I imagine I’ll have a loop to the effect of:<o:p></o:p>
<o:p>
Code:
</o:p>
[SIZE=3][FONT=Times New Roman]For i = vStart & xx to vEnd & xx<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]vTotal & xx = (i,vStd) + (i,vDup) + (i,vTax) ‘ Would be fields on Row i<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]Next i  [/FONT][/SIZE]
<o:p></o:p>
<o:p></o:p>
Then same routine needs to run again for vTotal & xx +1 and so on<o:p></o:p>
<o:p></o:p>



The questions:<o:p></o:p>
  • Am I am the right track?<o:p></o:p>
  • How do I establish xx in the above example<o:p></o:p>
<o:p></o:p>
Regards,<o:p></o:p>
<o:p></o:p>
Alan<o:p></o:p>
 
Hi Norie,
1. The reason why calculations are in code rather than in sheets is that I intend to distribute this code to people a long way from me. That means updates of software become very complex if code/calculations are on the sheets. It is a worthwhile idea though. Maybe I can set up some "temporary calculation pages" that never retain permanent data.

Your second question is the heart of the problem. This code is replicated 34 times with minor changes. That's why I am desperate to either reduce its size or replace it with something better - I suspect that using an array might solve the size problem and speed up execution.
The changes for the 34 iterations are mainly the writerow and then the wsIQ cells in the first 4 lines. Example if you look at the first six lines of procedure abovethe next iteration would start as follows:

Code:
[FONT=Times New Roman][SIZE=3]wsInv.Cells(WriteRowInv + 7, 1) = wsIQ.Cells(1, 27)[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 7, 2) = wsIQ.Cells(i, 27)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 7, 3) = wsIQ.Cells(i, 28)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 7, 4) = wsIQ.Cells(i, 29)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 7, 5) = Val(wsInv.Cells(WriteRowInv + 7, 2) / 100 * vTotal)[/FONT][/SIZE]

and the next:

Code:
[FONT=Times New Roman][SIZE=3]wsInv.Cells(WriteRowInv + 8, 1) = wsIQ.Cells(1, 30)[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 8, 2) = wsIQ.Cells(i, 30)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 8, 3) = wsIQ.Cells(i, 31)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 8, 4) = wsIQ.Cells(i, 32)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]     wsInv.Cells(WriteRowInv + 8, 5) = Val(wsInv.Cells(WriteRowInv + 8, 2) / 100 * vTotal)[/FONT][/SIZE]

and so on.

Thanks again for your time and trouble.

Regards,

Alan
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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