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

Vbalearner85

Board Regular
Joined
Jun 9, 2019
Messages
131
Office Version
  1. 2016
Platform
  1. 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)


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
    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)

Forum statistics

Threads
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.
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
Top