Vbalearner85
Board Regular
- Joined
- Jun 9, 2019
- Messages
- 139
- Office Version
- 2016
- Platform
- Windows
Hi, I am using the below macro for my analysis purposes. Able to sort out first, last, max, and min values for each range (LP, LN, HP & HN)-Refer to the screenshot
Looking for help for below:-
1. Find nth row value (if nth row count is more than the last row, take last row value) - nth row can vary and the row number is input in cell A1
2. Find the minimum value in the range (starting nth row value to last row value)
Regards,
Vbalearner
Looking for help for below:-
1. Find nth row value (if nth row count is more than the last row, take last row value) - nth row can vary and the row number is input in cell A1
2. Find the minimum value in the range (starting nth row value to last row value)
VBA Code:
Sub Analysis()
Dim firstrow As Long
Dim LastRow As Long, nthrow As Long
Dim myrange As Range, myrange1 As Range
Dim outrow As Long
firstrow = 2
outrow = 2
nthrow = Range("A1").Value2 - 1
Do Until Cells(firstrow, 4) = ""
LastRow = firstrow
Do Until Cells(LastRow, 4) <> Cells(LastRow + 1, 4)
LastRow = LastRow + 1
Loop
Set myrange = Range(Cells(firstrow, 3), Cells(LastRow, 3))
Cells(outrow, 6) = Cells(firstrow, 4)
Cells(outrow, 7) = Cells(firstrow, 3)
[COLOR=rgb(226, 80, 65)]If nthrow < LastRow Then Cells(outrow, 8) = Cells(nthrow, 3) Else Cells(outrow, 8) = Cells(LastRow, 3) ' This step is related to point 1 above..but is not working as expected[/COLOR]
Cells(outrow, 9) = Application.WorksheetFunction.Min(myrange)
Cells(outrow, 10) = Application.WorksheetFunction.Max(myrange)
firstrow = LastRow + 1
outrow = outrow + 1
Loop
ActiveSheet.Calculate
End Sub
Regards,
Vbalearner
Attachments
Last edited: