I’m creating a program in Excel that gets the highest and lowest numbers. I get the highest number but the lowest number stays always at 0. Please help me what I’m doing wrong.
This is the screenshot of the numbers I’m using:

This is the Code I created:
Sub Code()
Dim i As Integer
Dim max, min As Long
For i = 1 To 10
If Cells(i, 1).Value < min Then
min = Cells(i, 1).Value
End If
If Cells(i, 1).Value > max Then
max = Cells(i, 1).Value
End If
Next i
Cells(3, 4).Value = min
Cells(4, 4).Value = max
End Sub
Your
minvariable is defaulted to 0 when it is declared. Therefore, since none of your values are negative, theminvariable will remain zero (none of the values are ever less than it). TheIf...Thenstatement below will never be true:You have two options to fix this: