how to get smallest (min) & largest (max) value in a column in specific sheet using by VBA
<p>I have problem about my code, it can't show the smallest and largest value in Column A. I don't know where is the missing or wrong code...</p>

<p>my program open the txt file and input the data to the excel sheet. for example the data in column A is:</p>

<pre><code>0.23
0.19
0.19
0.13
0.15
0.18
0.19
0.25
0.25
0.22
0.13
</code></pre>

<p>and I type my code in VBA:</p>

<pre><code>Private Sub CommandButton1_Click()

Dim vMin, vMax
Dim mg As Range
Dim NOR, lastrow, currentrow As Long

filetoopen = Application.GetOpenFilename("Text File (*.txt),*.txt", , "Select", , False)

If VarType(filetoopen) = vbBoolean Then
    Exit Sub
End If

Workbooks.OpenText filetoopen, Origin _
    :=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
    , ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:= _
    False, Space:=False, other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1) _
    , Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
    Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1)), _
    TrailingMinusNumbers:=True

'get number of rows (row with value inside)-------------
With ActiveSheet
   NOR = .Cells(Rows.Count, "A").End(xlUp).Row
End With

'GET SMALLEST &amp; LARGEST VALUE FROM COLUMN A==========
With ActiveSheet
    lastrow = NOR

    For currentrow = 2 To lastrow
        Set mg = ThisWorkbook.Sheets(1).Rows(currentrow)

        'if row no data then no read------------------------
        If WorksheetFunction.CountA(mg) = 0 Then

        Else
            vMin = Application.WorksheetFunction.Min(Columns("A"))
            vMax = Application.WorksheetFunction.Max(Columns("A"))
        End If
    Next currentrow

End With

MsgBox "Minimum =  " &amp; vMin &amp; ", " &amp; "Maximum =  " &amp; vMax, vbInformation
MsgBox "last row A is = " &amp; NOR

End Sub
</code></pre>

<p>If I run this code, the <code>MessageBox</code> can't show the minimum (smallest) value and Maximum (largest) value in column A.</p>

<p>I hope you can help me to solve the problem.</p>

<p>aaf</p>