Alternate Line referances

eugene7

Board Regular
Joined
Apr 29, 2006
Messages
94
Hi,
I need to build a column of data with each alternate cell referencing a sequential list, with the odd cells averaging the data in the alternate cells thus...

B1 - references - A1
B2 - averages B1 & B3
B3 - references A2
B4 - averages B3 & B5
B5 - references A3
....

The problem is the (B) list has to be 35,940 cells long!

Is there a way to automate the writing of this list such that each alternate cell in list B references the next sequential cell in list A???
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
L

Legacy 98055

Guest
I tried to use Excel's fill down to repeat the pattern but I could not get it to work. Place this macro in your worksheet class and run it.

Assumes, as you stated in your example, range B1:B35940.

1130920.zip

<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#0000A0">Sub</font> Temp()
       <font color="#0000A0">Dim</font> a(1 <font color="#0000A0">To</font> 35940, 1 <font color="#0000A0">To</font> 1)
       <font color="#0000A0">Dim</font> x <font color="#0000A0">As</font> Long, y <font color="#0000A0">As</font> Long, r <font color="#0000A0">As</font> Range

       Application.ScreenUpdating = <font color="#0000A0">False</font>
       Me.EnableCalculation = <font color="#0000A0">False</font>

       <font color="#0000A0">For</font> <font color="#0000A0">Each</font> r <font color="#0000A0">In</font> Range("B1:B35940")
           y = y + 1
           <font color="#0000A0">If</font> y <font color="#0000A0">And</font> 1 <font color="#0000A0">Then</font>
               x = x + 1
               a(y, 1) = "=A" & CStr(x)
           <font color="#0000A0">Else</font>
               a(y, 1) = "=AVERAGE(B" & CStr(y - 1) & ",B" & CStr(y + 1) & ")"
           <font color="#0000A0">End</font> <font color="#0000A0">If</font>
       <font color="#0000A0">Next</font>

       Range("B1:B35940") = a
       Me.EnableCalculation = <font color="#0000A0">True</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("930200614012984").value=document.all("930200614012984").value.replace(/<br \/>\s\s/g,"");document.all("930200614012984").value=document.all("930200614012984").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("930200614012984").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="930200614012984" wrap="virtual">
Sub Temp()
Dim a(1 To 35940, 1 To 1)
Dim x As Long, y As Long, r As Range

Application.ScreenUpdating = False
Me.EnableCalculation = False

For Each r In Range("B1:B35940")
y = y + 1
If y And 1 Then
x = x + 1
a(y, 1) = "=A" & CStr(x)
Else
a(y, 1) = "=AVERAGE(B" & CStr(y - 1) & ",B" & CStr(y + 1) & ")"
End If
Next

Range("B1:B35940") = a
Me.EnableCalculation = True
End Sub</textarea>

1130920.zip
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi Steve

A formula solution. In B1:

Code:
=AVERAGE(OFFSET($A$1,-1+CEILING(ROW()/2,1),0,2-MOD(ROW(),2),1))
Copy down

Hope this helps
PGC
 

Forum statistics

Threads
1,136,263
Messages
5,674,710
Members
419,521
Latest member
Jasonnie

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
Top