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

var1var2var3var4
1356
5215
5824

<tbody>
</tbody>

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
Change_In_temperaturemassEnthalpy
484180
854172
1264195

<tbody>
</tbody>
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,216,075
Messages
6,128,662
Members
449,462
Latest member
Chislobog

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