vb如何选取textbox中的数据最大值和最小值
发布网友
发布时间:2023-10-11 19:58
我来回答
共2个回答
热心网友
时间:2024-12-08 19:04
本例子使用vba实现
关键函数:
Application.Max([a1:a4]) 可以取得当前excel文件中A列前4行中的最大值
Application.Max([b1:b4]) 可以取得当前excel文件中B列前4行中的最小值
代码
Private Sub CommandButton1_Click()
Dim txtPath1 As String, str1 As String, var1() As String, i As Integer, j As Integer
txtPath1 = "d:\test.txt"
j = 0
'读取txt文件
Open txtPath1 For Input As #1
Do Until EOF(1)
Line Input #1, str1
'将txt文件用,分隔保存到excel中显示一下,因为max/min函数只能对excel中
'的内容进行比较
str1 = Replace(str1, " ", ",")
var1 = Split(str1, ",")
For i = 0 To UBound(var1)
ThisWorkbook.Sheets.Application.Cells(j + 1, i + 1) = var1(i)
Next i
j = j + 1
Loop
Close #1
'取最大值
ThisWorkbook.Sheets.Application.Cells(j + 1, 1) = Application.Max([a1:a4])
'取最小值
ThisWorkbook.Sheets.Application.Cells(j + 1, 2) = Application.Min([b1:b4])
End Sub
热心网友
时间:2024-12-08 19:04
别用textbox了,太麻烦,用listview吧
-----------------------------------
不好意思,我也不会,你搜搜吧