Making variables from cell values in a range

exceltor

New Member
Joined
May 5, 2017
Messages
1
Sub practice()
Dim sht As Worksheet
Set sht = Worksheets("R401a")
Dim one, two As Range ' two will be treated the same as one, just haven't coded it yet.
Set one = sht.Range("one")
Set two = sht.Range("two")
Dim arr()
arr = sht.Range("one") ' one is a excel table I named
Dim i As Integer
For i = LBound(one) To UBound(one)
var1 = arr(i,1)
var2 = arr(i,2)
var3 = arr(i,3)
var4 = arr(i,4)
x= var1*var2*var3*var4 ' the actual equation is more complicated, using specific variables.
Next i
End Sub

[TABLE="width: 500"]
<tbody>[TR]
[TD]var1[/TD]
[TD]var2[/TD]
[TD]var3[/TD]
[TD]var4[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]5[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]2[/TD]
[TD]1[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]8[/TD]
[TD]2[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]

I was wondering if there was a way to make this more automated, as in, automatically making the var1, var2.... from the header row, then setting them equal to the column values. So that the same macro would work on, say
[TABLE="width: 500"]
<tbody>[TR]
[TD]Change_In_temperature[/TD]
[TD]mass[/TD]
[TD]Enthalpy[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]4180[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]5[/TD]
[TD]4172[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]6[/TD]
[TD]4195[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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