define variable range in a loop

ahadi

New Member
Joined
Jun 23, 2017
Messages
1
Dear friends,
I wish to perform statistical calculations in very huge pool of climate data.
what I need is to define a variable cell addresses and pass them to the formula to compute the output.

for example I have the following as Temperature or pressure in different columns for different days of very long historical data:
[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]Date/hour[/TD]
[TD]temperature[/TD]
[TD]pressure[/TD]
[TD]humidity[/TD]
[/TR]
[TR]
[TD]2017/6/1 03:00UTC[/TD]
[TD]23.3[/TD]
[TD]871.2[/TD]
[TD]21.5[/TD]
[/TR]
[TR]
[TD]2017/6/2 03:00UTC[/TD]
[TD]27.8[/TD]
[TD]870.6[/TD]
[TD]34.8[/TD]
[/TR]
[TR]
[TD]2017/6/3 3:00UTC[/TD]
[TD]26.8[/TD]
[TD]873.2[/TD]
[TD]27.8[/TD]
[/TR]
[TR]
[TD].....[/TD]
[TD]....[/TD]
[TD]...[/TD]
[TD]....[/TD]
[/TR]
</tbody>[/TABLE]

I wish to write a VBA which computes for example write average of certain number of cells in a columns in a cell and iterate it till the end of worksheet and for all sheets
I want to do exactly the following performance in Iterative loop:

iRow = 1
Do
Range("F32").Select
ActiveCell.FormulaR1C1 = "AvragePres"
Range("G32").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-31]C[-1]:R[-1]C[-1])"
Range("F33").Select
iRow = iRow + 1

Loop While iRow < 1600
in this code I wish to define variable cell address in a loop instead of constant cell address F3 or G32 and F33.

Many Thanks in advance for your kind efforts
Ahadi: vazife@gmail.com
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
just use something similar to your iRow variable...and then you can do this:

Code:
Range("F" & yourFVar)
Range("G" & yourGVar)
Range("F" & yourFVar + 1)

yourFVar = yourFVar + 1
yourGVar = yourGVar + 1
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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