Hello,
I'm working with a set of data which I have to manually unwrap and sort out all along the dataset. Essentially the slope of the data inverts and I have to go in and add on the difference to keep a continually increasing line instead of one which goes up and down.
As you can see in the image, the formula essentially just adds on the difference between the current value and the inflection point. There may be many inflections along the curve so the D7 and C7 references change on the next inflection point.
Is there any way to automatically do this in VBA? I have tried and its not really doing much.
Here is a snapshot of the workbook showing the unwrapping manually if that helps
https://i.imgur.com/dpwhHJB.png
I'm working with a set of data which I have to manually unwrap and sort out all along the dataset. Essentially the slope of the data inverts and I have to go in and add on the difference to keep a continually increasing line instead of one which goes up and down.
As you can see in the image, the formula essentially just adds on the difference between the current value and the inflection point. There may be many inflections along the curve so the D7 and C7 references change on the next inflection point.
Is there any way to automatically do this in VBA? I have tried and its not really doing much.
Code:
Dim rng As Range
Dim Maxima As Double
Dim RowNum As Long
Dim SelectCell As String
Dim ActiveCell As Range
Dim LastVal As Range
Dim n As Integer
Set rng = ActiveWorkbook.ActiveSheet.Range("C2:C836")
Maxima = Application.WorksheetFunction.Max(rng)
RowNum = Application.WorksheetFunction.Match(Maxima, rng, 0) + 1
SelectCell = Application.WorksheetFunction.Match(Application.WorksheetFunction.Max(Range("C:C")), Range("C:C"), 0) + 1
Set rng2 = ActiveWorkbook.ActiveSheet.Range("D" & SelectCell & ":D666")
Set LastVal = ActiveWorkbook.ActiveSheet.Range("C" & SelectCell - 1)
Dim i As Integer
For i = SelectCell To rng2.Rows.Count
Range("E" & i).Formula = (Range("D" & SelectCell - 1)) + (Abs(LastVal - (Range("C" & SelectCell + i))))
Next i
Here is a snapshot of the workbook showing the unwrapping manually if that helps
https://i.imgur.com/dpwhHJB.png