Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Correcting an extrapolation macro


Dear all,

Someone has designed a macro for me which should perform a linea
extrapolation on gaps in my dataset.

However, it appears to work across the rows as opposed to down th
columns. I require it to work on columns F-I and R-U (inclusive) a
opposed to the whole dataset.

Would anybody be able to correct the macro below to achieve this?


Sub Pfil()

Dim i As Long
Dim r As Long
Dim er As Long
Dim sc As Long
Dim ec As Long
Dim src As Range
Dim dest As Range

'Start Row
r = 2
'Last row
er = Range("a65536").End(xlUp).Row - 1
'Start column (G) = first column + 1
sc = 7
'End column (L) = last column - 1
ec = 12

'Do all rows of data
For i = 1 To er

'If first Col is blank, fill
If Cells(r, sc - 1) = "" Then
Set src = Range(Cells(r, sc), Cells(r, ec))
Set dest = Range(Cells(r, sc - 1), Cells(r, ec))
src.AutoFill Destination:=dest, Type:=xlFillSeries
End If
'If last Col is blank, fill
If Cells(r, ec + 1) = "" Then
Set src = Range(Cells(r, sc), Cells(r, ec))
Set dest = Range(Cells(r, sc), Cells(r, ec + 1))
src.AutoFill Destination:=dest, Type:=xlFillSeries
End If
r = r + 1
Next i

End Sub


I hope someone is able to tackle this for me!

Many thanks for your help,
Steve

--
smurray44
-----------------------------------------------------------------------
smurray444's Profile: http://www.excelforum.com/member.php...fo&userid=2895
View this thread: http://www.excelforum.com/showthread.php?threadid=50670

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Correcting an extrapolation macro

Steve,

Did you try my macro?

Assuming that your step in the Time dimension is always consistent, your data is sorted based on the
identifier (station 1, etc.), and that your identifier is in column A - try the macro below, on a
copy of your data.

HTH,
Bernie
MS Excel MVP

Sub FillInBlanks()
Dim myCell As Range
Dim i As Integer
Dim myRange As Range

Set myRange = Range("A:A")

For i = 6 To 13

' Interpolation First
For Each myCell In Columns(i).SpecialCells(xlCellTypeBlanks)
With myRange
If (.Cells(myCell.Row).Value = _
.Cells(myCell.End(xlUp).Row).Value) And _
(.Cells(myCell.Row).Value = _
.Cells(myCell.End(xlDown).Row).Value) Then
myCell.Value = myCell.End(xlDown).Value + _
(myCell.Row - myCell.End(xlDown).Row) _
* (myCell.End(xlUp).Value - myCell.End(xlDown).Value) / _
(myCell.End(xlUp).Row - myCell.End(xlDown).Row)
End If
End With
Next myCell

'Now Extrapolation
For Each myCell In Columns(i).SpecialCells(xlCellTypeBlanks)
'Interpolate if a cell above has been filled in
With myRange
If (.Cells(myCell.Row).Value = _
.Cells(myCell.End(xlUp).Row).Value) And _
(.Cells(myCell.Row).Value = _
.Cells(myCell.End(xlDown).Row).Value) Then
myCell.Value = myCell.End(xlDown).Value + _
(myCell.Row - myCell.End(xlDown).Row) _
* (myCell.End(xlUp).Value - myCell.End(xlDown).Value) / _
(myCell.End(xlUp).Row - myCell.End(xlDown).Row)
ElseIf (.Cells(myCell.Row).Value < _
.Cells(myCell.End(xlUp).Row).Value) Then
myCell.Value = myCell.End(xlDown).Value + _
(myCell.Row - myCell.End(xlDown).Row) _
* (myCell.End(xlDown)(2).Value - myCell.End(xlDown).Value) / _
(myCell.End(xlDown)(2).Row - myCell.End(xlDown).Row)
Else
myCell.Value = myCell.End(xlUp).Value + _
(myCell.Row - myCell.End(xlUp).Row) _
* (myCell.End(xlUp)(0).Value - myCell.End(xlUp).Value) / _
(myCell.End(xlUp)(0).Row - myCell.End(xlUp).Row)
End If
End With
Next myCell

Next i

End Sub

"smurray444" wrote in message
...

Dear all,

Someone has designed a macro for me which should perform a linear
extrapolation on gaps in my dataset.

However, it appears to work across the rows as opposed to down the
columns. I require it to work on columns F-I and R-U (inclusive) as
opposed to the whole dataset.

Would anybody be able to correct the macro below to achieve this?


Sub Pfil()

Dim i As Long
Dim r As Long
Dim er As Long
Dim sc As Long
Dim ec As Long
Dim src As Range
Dim dest As Range

'Start Row
r = 2
'Last row
er = Range("a65536").End(xlUp).Row - 1
'Start column (G) = first column + 1
sc = 7
'End column (L) = last column - 1
ec = 12

'Do all rows of data
For i = 1 To er

'If first Col is blank, fill
If Cells(r, sc - 1) = "" Then
Set src = Range(Cells(r, sc), Cells(r, ec))
Set dest = Range(Cells(r, sc - 1), Cells(r, ec))
src.AutoFill Destination:=dest, Type:=xlFillSeries
End If
'If last Col is blank, fill
If Cells(r, ec + 1) = "" Then
Set src = Range(Cells(r, sc), Cells(r, ec))
Set dest = Range(Cells(r, sc), Cells(r, ec + 1))
src.AutoFill Destination:=dest, Type:=xlFillSeries
End If
r = r + 1
Next i

End Sub


I hope someone is able to tackle this for me!

Many thanks for your help,
Steve M


--
smurray444
------------------------------------------------------------------------
smurray444's Profile: http://www.excelforum.com/member.php...o&userid=28956
View this thread: http://www.excelforum.com/showthread...hreadid=506707



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup & Extrapolation alawi Excel Worksheet Functions 3 March 17th 09 05:50 PM
Extrapolation of non linear data andy duncan Excel Worksheet Functions 8 August 8th 07 02:46 PM
Correcting an extrapolation macro smurray444 Excel Discussion (Misc queries) 2 February 1st 06 10:29 AM
Automating Extrapolation smurray444[_3_] Excel Programming 4 January 29th 06 01:20 PM
Automating Extrapolation smurray444 Excel Discussion (Misc queries) 1 January 29th 06 01:09 PM


All times are GMT +1. The time now is 08:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"