Unwrapping data using VBA

rinosaur

New Member
Joined
Jan 20, 2018
Messages
1
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.

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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Where is the chart code? What values are U using for the chart? Seems like U might want to chart a named range. Jon Peltier has some great chart stuff on his site. HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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