# Analysis - Nth Value in Range and Min value after nth value

#### Vbalearner85

##### Board Regular
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)

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

• Analysis.JPG
69.9 KB · Views: 11
Last edited:

### Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Regards

Replies
6
Views
176
Replies
18
Views
212
Replies
3
Views
140
Replies
16
Views
352
Replies
14
Views
208

1,147,455
Messages
5,741,218
Members
423,649
Latest member
steel1968

### 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.

### Which adblocker are you using?

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

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