kblaine123
Board Regular
- Joined
- Oct 10, 2009
- Messages
- 74
I's there a way to put this excel formula in the VBA sub below ?
If(min(D3:d$4)>e2,min(d3:d$4)-e2,0)
Cell d$4 is dynamic.....it could be 50 or 1000
I was thinking i could write a For Next statement like shown below in bold.....but I can't figure out how to write it for the min statement.
Sub AnalyzeData()
Dim i As Integer
Dim LastRow As Integer
Dim avReturn As Double
Dim stDev As Double
Dim vrnc As Double
LastRow = Sheets("Data").UsedRange.Row - 2 + Sheets("Data").UsedRange.Rows.Count
Sheets("Data").Range("L2") = LastRow
For i = 3 To LastRow
If Sheets("Data").Range("B" & i) >= Sheets("Data").Range("E" & (i - 1)) And Sheets("Data").Range("D" & i) > Sheets("Data").Range("E" & (i - 1)) Then
Sheets("Data").Range("J" & i) = (Sheets("Data").Range("D" & i) - Sheets("Data").Range("E" & i - 1))
End If
Next i
If(min(D3:d$4)>e2,min(d3:d$4)-e2,0)
Cell d$4 is dynamic.....it could be 50 or 1000
I was thinking i could write a For Next statement like shown below in bold.....but I can't figure out how to write it for the min statement.
Sub AnalyzeData()
Dim i As Integer
Dim LastRow As Integer
Dim avReturn As Double
Dim stDev As Double
Dim vrnc As Double
LastRow = Sheets("Data").UsedRange.Row - 2 + Sheets("Data").UsedRange.Rows.Count
Sheets("Data").Range("L2") = LastRow
For i = 3 To LastRow
If Sheets("Data").Range("B" & i) >= Sheets("Data").Range("E" & (i - 1)) And Sheets("Data").Range("D" & i) > Sheets("Data").Range("E" & (i - 1)) Then
Sheets("Data").Range("J" & i) = (Sheets("Data").Range("D" & i) - Sheets("Data").Range("E" & i - 1))
End If
Next i