Calculating Slope Using Macros

Melpp

New Member
Joined
May 3, 2011
Messages
29
I want to be able to calculate the downwards slope after peaks. The data is very noisy and contains many peaks. Is there any easy way to automate this using Excel VBA Macros.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You need to be more precise with your question.

What defines the peak?
What defines a slope?
What is the data that is being generated?

An example would help immensely.

Otherwise, yes, there is an easy way to automate this using Excel VBA Macros.
 
Upvote 0
The data is collected over time and the y-axis scale ranges from 0--> 60. A peak is defined as a high value and I am looking for excel to calculate the slope from the peak back to baseline. A task is repeated about 5 times and so there are multiple peaks and thus multiple slopes to calculate.
 
Upvote 0
I wrote the following code to check is the value of the cell is larger than the 5 cells after it and the 4 cells before it. I am not sure why but it does not seem to output anything. Any advice?

Set FirstCell = Cells(5, 1)

No = 5

For i = 0 To (Last_Row2)
If FirstCell.Offset(i, 0) > FirstCell.Offset(i + 1, 0) Then
If FirstCell.Offset(i + 2, 0) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i + 3, 0) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i + 4, 0) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i + 5, 0) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i - 1) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i - 2) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i - 3) < FirstCell.Offset(0, 0) Then
If FirstCell.Offset(i - 4) < FirstCell.Offset(0, 0) Then
Max = FirstCell.Offset(0, 0).Value
Range(Cells(No, 10)).Value = Max
No = No + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next i
 
Upvote 0
The data is collected over time and the y-axis scale ranges from 0--> 60. A peak is defined as a high value and I am looking for excel to calculate the slope from the peak back to baseline. A task is repeated about 5 times and so there are multiple peaks and thus multiple slopes to calculate.
Your reply is arbitary and I didn't find your answers accurate enough to understand your problem (can't comment if anyone else did)

Do you mean if you have a sequence of: 0, 1, 2, 1, 0, 1 then 2 would be the peak?

Then, is the slope 2 (peak - mininum number before or after identified peak, i.e. 2 - green 0 or red 0 - 2 = -2)?

What happens if the sequence then becomes: 0, 1, 2, 1, 0, 1, 2, 3, 4, 4, 5, 6, 5, 6, 7, 6, 7? What is the peak now? What is the base now? What is the slope value you are trying to calculate?

As requested below, it would be much clearer if you posted an example of your data (Excel Jeanie is a good way to post a screenshot of your worksheet) or tried to explain with much more clarity
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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