Interpolated values referenced to time.

rosscu

New Member
Joined
Dec 7, 2017
Messages
2
Hi,


I have data in columns B and C that are referenced to time in column A. Time in Column A is in format hh:mm:ss and starts at 00:00:00. I have approx 5000 rows of data.


The data in B and C are Easting and Northings that have been acquired at randomly increasing time increments between 1 and 25 seconds, for example:


[TABLE="width: 261"]
<tbody>[TR]
[TD]Acquired time[/TD]
[TD]Easting[/TD]
[TD]Northing[/TD]
[/TR]
[TR]
[TD]00:00:04[/TD]
[TD]712876[/TD]
[TD]9545869[/TD]
[/TR]
[TR]
[TD]00:00:07[/TD]
[TD]712871[/TD]
[TD]9545875[/TD]
[/TR]
[TR]
[TD]00:00:11[/TD]
[TD]712865[/TD]
[TD]9545882[/TD]
[/TR]
[TR]
[TD]00:00:14[/TD]
[TD]712860[/TD]
[TD]9545887[/TD]
[/TR]
[TR]
[TD]00:00:17[/TD]
[TD]712855[/TD]
[TD]9545893[/TD]
[/TR]
[TR]
[TD]00:00:21[/TD]
[TD]712848[/TD]
[TD]9545900[/TD]
[/TR]
[TR]
[TD]00:00:24[/TD]
[TD]712843[/TD]
[TD]9545905[/TD]
[/TR]
[TR]
[TD]00:00:27[/TD]
[TD]712838[/TD]
[TD]9545911[/TD]
[/TR]
</tbody>[/TABLE]



I would like Easting and Northings every second, interpolated linearly.


I would very much appreciate it if anyone could tell me how to do this in excel!


Thank you,
Ross
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Start data:


Book1
ABC
1Acquired timeEastingNorthing
200:00:047128769545869
300:00:077128719545875
400:00:117128659545882
500:00:147128609545887
600:00:177128559545893
700:00:217128489545900
800:00:247128439545905
900:00:277128389545911
Sheet1


End data:


Book1
ABC
1Acquired timeEastingNorthing
200:00:047128769545869
300:00:05712874.39545871
400:00:06712872.79545873
500:00:077128719545875
600:00:08712869.59545877
700:00:097128689545879
800:00:10712866.59545880
900:00:117128659545882
1000:00:12712863.39545884
1100:00:13712861.79545885
1200:00:147128609545887
1300:00:15712858.39545889
1400:00:16712856.79545891
1500:00:177128559545893
1600:00:18712853.39545895
1700:00:19712851.59545897
1800:00:20712849.89545898
1900:00:217128489545900
2000:00:22712846.39545902
2100:00:23712844.79545903
2200:00:247128439545905
2300:00:25712841.39545907
2400:00:26712839.79545909
2500:00:277128389545911
Sheet1


Macro:

Code:
Public Sub InterpolateEastingNorthing()

Dim lastRow As Long
Dim thisRow As Long
Dim lastDate As Date
Dim lastEasting As Double
Dim lastNorthing As Double
Dim thisDate As Date
Dim thisEasting As Double
Dim thisNorthing As Double
Dim missingRows As Long
Dim newRow As Long

' Find the last row of data
lastRow = Cells(Rows.Count, "A").End(xlUp).Row

' Record the values from the second row as the starting values
lastDate = Range("A2").Value
lastEasting = Range("B2").Value
lastNorthing = Range("C2").Value

' Start processing from row 3
thisRow = 3

' Process all rows
Do While thisRow <= lastRow
    ' Record the values from the current row
    thisDate = Cells(thisRow, "A").Value
    thisEasting = Cells(thisRow, "B").Value
    thisNorthing = Cells(thisRow, "C").Value
    
    ' Calculate how many rows are missing (86400 is the number of seconds in a day)
    missingRows = (thisDate - lastDate) * 86400 - 1
    
    ' Are we missing some rows?
    If missingRows > 0 Then
        ' Insert new rows and shift the data down
        Rows(CStr(thisRow) & ":" & CStr(thisRow + missingRows - 1)).Insert Shift:=xlDown
        
        ' Populate data into each new row based on difference between the numbers
        For newRow = 1 To missingRows
            Cells(thisRow + newRow - 1, "A").Value = lastDate + TimeSerial(0, 0, newRow)
            Cells(thisRow + newRow - 1, "B").Value = lastEasting + (thisEasting - lastEasting) / (missingRows + 1) * newRow
            Cells(thisRow + newRow - 1, "C").Value = lastNorthing + (thisNorthing - lastNorthing) / (missingRows + 1) * newRow
        Next newRow
        
        ' We've moved the last row and the current row
        lastRow = lastRow + missingRows
        thisRow = thisRow + missingRows
    End If
    
    ' Save the current values
    lastDate = thisDate
    lastEasting = thisEasting
    lastNorthing = thisNorthing
    
    ' Move to the next row
    thisRow = thisRow + 1
Loop

End Sub

WBD
 
Upvote 0
Wow. That was very quick and works perfectly. I am not worthy.

I'm pushing my luck here, but do you know how can I add more pairs of Easting/Northings to the input data? For example, pairs of Easting/Northings up to columns BX/BY? They would be referenced to the same time in column A as the originals were in columns B and C.

Thank you very much you absolute legend.
 
Upvote 0
Hey @rosscu,

This should do as many columns as you have headings for in the first row:

Code:
Public Sub InterpolateEastingNorthing()

Dim lastRow As Long
Dim thisRow As Long
Dim lastCol As Long
Dim thisCol As Long
Dim lastDate As Date
Dim thisDate As Date
Dim lastValues As Variant
Dim thisValues As Variant
Dim missingRows As Long
Dim newRow As Long

' Find the last row and column of data
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column

' Record the values from the second row as the starting values
lastDate = Range("A2").Value
lastValues = Range(Cells(2, 2), Cells(2, lastCol)).Value

' Start processing from row 3
thisRow = 3

' Process all rows
Do While thisRow <= lastRow
    ' Record the values from the current row
    thisDate = Cells(thisRow, "A").Value
    thisValues = Range(Cells(thisRow, 2), Cells(thisRow, lastCol)).Value
    
    ' Calculate how many rows are missing (86400 is the number of seconds in a day)
    missingRows = (thisDate - lastDate) * 86400 - 1
    
    ' Are we missing some rows?
    If missingRows > 0 Then
        ' Insert new rows and shift the data down
        Rows(CStr(thisRow) & ":" & CStr(thisRow + missingRows - 1)).Insert Shift:=xlDown
        
        ' Populate data into each new row based on difference between the numbers
        For newRow = 1 To missingRows
            Cells(thisRow + newRow - 1, "A").Value = lastDate + TimeSerial(0, 0, newRow)
            For thisCol = 2 To lastCol
                Cells(thisRow + newRow - 1, thisCol).Value = lastValues(1, thisCol - 1) + (thisValues(1, thisCol - 1) - lastValues(1, thisCol - 1)) / (missingRows + 1) * newRow
            Next thisCol
        Next newRow
        
        ' We've moved the last row and the current row
        lastRow = lastRow + missingRows
        thisRow = thisRow + missingRows
    End If
    
    ' Save the current values
    lastDate = thisDate
    lastValues = thisValues
    
    ' Move to the next row
    thisRow = thisRow + 1
Loop

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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