Hey all,
I'm trying to streamline a macro that was given to me by a colleague. In it, one of the tasks is to find the maximum value from a long list of data and then do some calculations on it.
The original has one cell at the top of the list that uses the "=Max" function in it to find the value of the maximum but I need to know what row it is in. I used the following code to find the row number write it in a cell. The FindData variable is assigned to the maximum value.
Sub FindCells()
Dim FindData As Double
Dim Row_Number As Integer
FindData = ActiveSheet.Cells(6, 15).Value
Range("L5:L2000").Find(What:=FindData, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Row_Number = ActiveCell.Row
ActiveSheet.Cells(2, 14).Value = Row_Number
End Sub
If FindData is used as a "Long" data type the code runs, but it doesn't necessarily return the maximum value, just a value that happens to contain some of the maximum values digits. I need the find function to return exactly the value that's assigned to the FindData variable. The maximum value is a rational number with several decimal places.
Any help would be great!
Thanks!
I'm trying to streamline a macro that was given to me by a colleague. In it, one of the tasks is to find the maximum value from a long list of data and then do some calculations on it.
The original has one cell at the top of the list that uses the "=Max" function in it to find the value of the maximum but I need to know what row it is in. I used the following code to find the row number write it in a cell. The FindData variable is assigned to the maximum value.
Sub FindCells()
Dim FindData As Double
Dim Row_Number As Integer
FindData = ActiveSheet.Cells(6, 15).Value
Range("L5:L2000").Find(What:=FindData, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Row_Number = ActiveCell.Row
ActiveSheet.Cells(2, 14).Value = Row_Number
End Sub
If FindData is used as a "Long" data type the code runs, but it doesn't necessarily return the maximum value, just a value that happens to contain some of the maximum values digits. I need the find function to return exactly the value that's assigned to the FindData variable. The maximum value is a rational number with several decimal places.
Any help would be great!
Thanks!