PDA

View Full Version : Nested Loops-In What Sequence?



altbeb
06-28-2010, 03:35 AM
iHi:

My excel programming is slowly getting better, but my knowledge falls way short of those on these boards.. :yes..

i am attempting to determine the trend of a list of data.. and once the trend of the data is determined.. then l have to determine the maximum or minimum value of the data trend, as this data is sinusoidal.. there in lies my problem.. l have written the following so far:

:confused:

Public Sub MaxMinVal()

Dim ChanelSelRnge As Range
Dim Val1 As Double
Dim Val2 As Double
Dim Val3 As Double
Dim c As Range

Dim i As Integer
Dim SFileName As String
Dim ChannelNums As Integer


ChannelsNum = Application.WorksheetFunction.CountIf(Sheets("CorrectedData").Range("ChanelSelRnge"), "*")

MsgBox "The result is " & ChannelsNum

'select the first range in ChanelSelRnge

For i = 1 To ChannelNums

For Each c In Range(Range("ChanelSelRnge")(i))

Val1 = Range(Range("ChanelSelRnge")(i))
Val2 = Range(Range("ChanelSelRnge")(i + 1))
Val3 = Range(Range("ChanelSelRnge")(i + 2))

' Comparing the values of the two consecutive cells
If Val1 < Val2 And Val2 < Val3 Then


Val1 = Range(Range("ChanelSelRnge")(i + 3))
Val2 = Range(Range("ChanelSelRnge")(i + 4))
Val3 = Range(Range("ChanelSelRnge")(i + 5))

If Val1 < Val2 And Val2 < Val3 Then

Do Until Val1 > Val2 And Val2 < Val3





is this the method to follow. and am l doing the loop nesting correctly?:think:

mdmackillop
06-28-2010, 03:54 AM
Can you post sample data? It makes things much clearer.

altbeb
06-28-2010, 03:15 PM
Hi:

l had to delete the charts of the data to get the file under 1M.. but the essential data is there.. TIA


altbeb