Automatically extrapolating data?

JeremyBowyer

New Member
Joined
Jan 20, 2014
Messages
2
Hi guys, I've been lurking for a while and have gotten a lot of valuable information from the advice given by you folks, so thanks for that.

I have what I expect will be a simple problem (if there's a way to solve it). First off I'm working in Excel 2013 64-bit. Basically I'm going to have large amounts of data with gaps that I need to fill in using what I know from the data I do have. That's not very clear so let me give you an example.


My data looks like this:

YearCountryXY
1901Germany111
1902Germany
1903Germany
1904Germany
1905Germany15
1906Germany
1907Germany
1908Germany
1909Germany
1910Germany1010
1911Germany
1912Germany
1913Germany7
1914Germany
1915Germany
1916Germany
1917Germany
1918Germany12
1919Germany
1920Germany2014

<tbody>
</tbody>


I want it to look like this:

YearCountryXY
1901Germany111
1902Germany212
1903Germany313
1904Germany414
1905Germany515
1906Germany614
1907Germany713
1908Germany812
1909Germany911
1910Germany1010
1911Germany119
1912Germany128
1913Germany137
1914Germany148
1915Germany159
1916Germany1610
1917Germany1711
1918Germany1812
1919Germany1913
1920Germany2014

<tbody>
</tbody>


I'm only using the red text to indicate what was added; I don't need any help formatting the text, I know how to do that much. :cool:


Anyway, in other words I want to fill in the missing gaps as if that data increased/decreased linearly over that time period. I know how to calculate it manually, but I was wondering if there was a way to do it en masse automatically.

Any help will be appreciated.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This assumes X and Y are columns C:D

Code:
[color=darkblue]Sub[/color] Fill_XY()
    
    [color=darkblue]Dim[/color] col [color=darkblue]As[/color] Range, rngArea [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] lStart [color=darkblue]As[/color] [color=darkblue]Long[/color], lStop [color=darkblue]As[/color] [color=darkblue]Long[/color], lStep [color=darkblue]As[/color] [color=darkblue]Long[/color]
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] col [color=darkblue]In[/color] Range("C:D").Columns
        [color=darkblue]For[/color] [color=darkblue]Each[/color] rngArea [color=darkblue]In[/color] col.SpecialCells(xlCellTypeBlanks).Areas
            lStart = rngArea(0).Value
            lStop = rngArea(rngArea.Count + 1)
            lStep = IIf(lStop > lStart, 1, -1)
            rngArea(1) = lStart + lStep
            [color=darkblue]If[/color] rngArea.Count > 1 [color=darkblue]Then[/color]
                rngArea.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Step:=lStep, Stop:=lStop
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]Next[/color]
    Next col
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Thanks very much Alpha.

I've been toying around with the macro you provided and it's not exactly what I need. It seems like what it does is adds or subtracts 1 for each cell going down the column. What I need is a way to bridge the gap between 2 values, if that makes sense.


For instance. If I use your macro in this modified example table, it doesn't work:

YearCountryXY
1901Germany10110
1902Germany
1903Germany
1904Germany
1905Germany 150
1906Germany
1907Germany
1908Germany
1909Germany
1910Germany100100
1911Germany
1912Germany
1913Germany 70
1914Germany
1915Germany
1916Germany
1917Germany
1918Germany 120
1919Germany
1920Germany200140

<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>




It produces this result:

YearCountryXY
1901Germany10110
1902Germany11111
1903Germany12112
1904Germany13113
1905Germany14150
1906Germany15149
1907Germany16148
1908Germany17147
1909Germany18146
1910Germany100100
1911Germany10199
1912Germany10298
1913Germany10370
1914Germany10471
1915Germany10572
1916Germany10673
1917Germany10774
1918Germany108120
1919Germany109121
1920Germany200140

<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>



What I'm looking for is a way to fill in those gaps based on both the starting point data and the end point data for each gap. Does that make sense?
 
Upvote 0
It does make sense sort of. Given the data set in your first post, the gaps count was exactly the same amount as needed to be bridged. "Bridge the gaps" can be interpreted many ways. Do you want to round decimal values?


Try this one...

Code:
[color=darkblue]Sub[/color] Fill_XY()
    
    [color=darkblue]Dim[/color] col [color=darkblue]As[/color] Range, rngArea [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] lStart [color=darkblue]As[/color] [color=darkblue]Single[/color], lStop [color=darkblue]As[/color] [color=darkblue]Single[/color], lStep [color=darkblue]As[/color] [color=darkblue]Single[/color]
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] col [color=darkblue]In[/color] Range("C:D").Columns
        [color=darkblue]For[/color] [color=darkblue]Each[/color] rngArea [color=darkblue]In[/color] col.SpecialCells(xlCellTypeBlanks).Areas
            [color=darkblue]Set[/color] rngArea = rngArea(0).Resize(rngArea.Count + 1)
            lStart = rngArea(1).Value
            lStop = rngArea(rngArea.Count + 1)
            lStep = (lStop - lStart) / rngArea.Count
            rngArea.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Step:=lStep, Stop:=lStop
        [color=darkblue]Next[/color]
    Next col
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,831
Members
449,471
Latest member
lachbee

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