find peak and trough in data

qwertyjjj

New Member
Joined
Dec 17, 2007
Messages
14
I need to find peaks and troughs in a dataset and then draw horizontal lines on a graph.
Starting with a trough at the top, hjow do I find the next peak, then trough, then peak?

Code:
2112	3739900.0
2111.5	0.0
2111	40477000.0
2110.5	36991400.0
2110	47048700.0
2109.5	29540100.0
2109	10913400.0
2108.5	34449400.0
2108	205151504.0
2107.5	68120800.0
2107	72696300.0
2106.5	266594600.0
2106	85799700.0
2105.5	110162300.0
2105	195678904.0
2104.5	77769900.0
2104	38941800.0
2103.5	55083200.0
2103	60785700.0
2102.5	111992400.0
2102	273232604.0
2101.5	74710100.0
2101	126955200.0
2100.5	213616000.0
2100	111807000.0
2099.5	74419200.0
2099	74671300.0
2098.5	73661200.0
2098	53189400.0
2097.5	189451500.0
2097	40384400.0
2096.5	41221800.0
2096	226907200.0
2095.5	63465900.0
2095	54453500.0
2094.5	37356900.0
2094	28794400.0
2093.5	51220700.0
2093	30095500.0
2092.5	205854908.0
2092	20000300.0
2091.5	6395900.0
2091	159627204.0
2090.5	6859800.0
2090	22735400.0
2089.5	3731200.0
2089	11287200.0
2088.5	11990900.0
2088	31076900.0
2087.5	58287700.0
2087	47212400.0
2086.5	83859800.0
2086	67156800.0
2085.5	70703400.0
2085	66689600.0
2084.5	83639500.0
2084	102453800.0
2083.5	83306100.0
2083	75943700.0
2082.5	61760100.0
2082	261906500.0
2081.5	67219200.0
2081	215789300.0
2080.5	365248800.0
2080	38651500.0
2079.5	56484000.0
2079	34411200.0
2078.5	34306600.0
2078	30620400.0
2077.5	28018900.0
2077	16706800.0
2076.5	118554996.0
2076	66922400.0
2075.5	28401400.0
2075	9248600.0
2074.5	18630600.0
2074	5535300.0
2073.5	0.0
2073	0.0
2072.5	0.0
2072	0.0
2071.5	11298800.0
2071	5780300.0
2070.5	7013900.0
2070	25018200.0
2069.5	13329300.0
2069	11132100.0
2068.5	38949000.0
2068	19744200.0
2067.5	24212200.0
2067	218693304.0
2066.5	27039300.0
2066	10147400.0
2065.5	39206600.0
2065	10734500.0
2064.5	2513700.0
2064	5053000.0
2063.5	3244900.0
2063	3480800.0
2062.5	6290000.0
2062	6462000.0
2061.5	42252700.0
2061	0.0
2060.5	0.0
2060	8165500.0
2059.5	0.0
2059	0.0
2058.5	0.0
2058	0.0
2057.5	0.0
2057	0.0
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
This macro will identify the Peaks and Troughs from Column B in Columns C...
Code:
Sub PeaksAndTroughs()
  Dim R As Long, Data As Variant, PnT As Variant
  Data = Range("B1", Cells(Rows.Count, "B").End(xlUp))
  ReDim PnT(1 To UBound(Data), 1 To 1)
  For R = 2 To UBound(Data) - 3
    If Data(R - 1, 1) < Data(R, 1) And Data(R + 1, 1) < Data(R, 1) Then
      PnT(R, 1) = "Peak"
    ElseIf Data(R - 1, 1) > Data(R, 1) And Data(R + 1, 1) > Data(R, 1) Then
      PnT(R, 1) = "Trough"
    End If
  Next
  Range("C1").Resize(UBound(PnT)) = PnT
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,438
Members
452,326
Latest member
johnshaji

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