Insert row bewteen every data set , then calcuate the differnce and populate

jwalkerack

Board Regular
Joined
Jun 19, 2013
Messages
81
Hello everyone , i m not sure if i m saying this right but here goes . i have data set of two values . For example time versus distance. For each time value there is a corresponding distance. i would like to be able have a macro that inserts a row between every time and distance point i have . Next i would like to have a macro that automatically calcuates and populates the difference between the rows.

So my original data set would be as follows

time Distance
61
92
153
254
675
896
1007
1408
1899
220

<tbody>
</tbody>

This is it with inserted rows one after each column that has data

timeDistance
61
92
153
254
675
896
1007
1408
1899
22010

<tbody>
</tbody>

i know the calculation to work out the difference between the 2 value. Is the bottom value subtracted by the top value and then halved and added to the bottom value . IE 2-1= 1/2= 0.5 +1= 1.5 so 1.5 would be the second row entry for distance field . Is it possible to have a two macros that will constantly allow me to double my data set ?


i want to have something like this in the end and be able to repeat the several times , each time increasing my dataset

time Distance
61
7.51.5
92
122.5
153
203.5
254
464.5
675
785.5
896
94.56.5
1007
1207.5
1408
164.58.5
1899
204.59.5
22010

<colgroup><col><col></colgroup><tbody>
</tbody>
61
7.51.5
92
122.5
153
203.5
254
464.5
675
785.5
896
94.56.5
1007
1207.5
1408
164.58.5
1899
204.59.5
22010

<colgroup><col><col></colgroup><tbody>
</tbody>
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
<font face=Courier New>Option Explicit<br><br><br><SPAN style="color:#00007F">Sub</SPAN> InterpolateTD()<br><SPAN style="color:#007F00">' Set cursor somewhere in range _<br>  where interpolation is required. _<br>  The macro will insert a row between _<br>  each of the existing rows and interpolate _<br>  between the data.</SPAN><br>  <br>    <SPAN style="color:#00007F">Dim</SPAN> rRng <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> lRC <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#007F00">' set range object to topp left cell of range</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> rRng = ActiveCell.CurrentRegion.Cells(1, 1)<br>    <br>    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> rRng <> vbNullString<br>        <SPAN style="color:#00007F">If</SPAN> IsNumeric(rRng) And rRng.Offset(0, 1) <> vbNullString <SPAN style="color:#00007F">Then</SPAN><br>            rRng.Offset(1, 0).EntireRow.Insert<br>            <SPAN style="color:#00007F">With</SPAN> rRng.Offset(1, 0)<br>                .Value = (rRng.Value + rRng.Offset(2, 0).Value) / 2<br>                .Offset(0, 1).Value = (rRng.Offset(0, 1).Value + rRng.Offset(2, 1).Value) / 2<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#007F00">' set the range 2 rows down to repeat the action</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> rRng = rRng.Offset(2, 0)<br>    <SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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