VB逐行读取excel里的数,并要计算

来源:百度知道 编辑:UC知道 时间:2024/05/23 20:28:02
VB逐行读取excel里的数,目的是寻找cells(X,Y)=Ts的行号或者是 cells(X1,Y1)<Ts<cells(X2,Y2)的x1的位置
自己写了一段:
i = 1
If xlApp.Cells(i, 2).Value < Ts Then i = i + 1
If xlApp.Cells(i, 2).Value < Ts Then i = i + 1
ElseIf xlApp.Cells(i, 2).Value > Ts Then ii = i
ElseIf xlApp.Cells(i, 2).Value = Ts Then ii = i
End If
End If
ii = i
但不对,有问题,自己也觉得很乱。
在线急等!!!!!!!!

是挺乱的。。
或者是 cells(X1,Y1)<Ts<cells(X2,Y2)的x1的位置 这个没在明白

首先
If xlApp.Cells(i, 2).Value < Ts Then i = i + 1
If xlApp.Cells(i, 2).Value < Ts Then i = i + 1
这两个IF是一样的。何必写两次?
ElseIf xlApp.Cells(i, 2).Value > Ts Then ii = i
ElseIf xlApp.Cells(i, 2).Value = Ts Then ii = i
这为什么不写成 ElseIf xlApp.Cells(i, 2).Value > =Ts Then ii = i

你是只要查找B列=Ts的行号吗?

dim srt as string
dim i as Integer
srt ="等于TS的行号有"
for i = 1 to 65536
If xlApp.Cells(i, 2).Value = Ts Then
srt= srt & "," & i
end if
next i
msgbox srt

没跑过。。不知道行不行。。

寻找等于TS的单元格位置
dim x,y
dim n() as string
x=1
for x=1 to 65535 '循环从1到65535
y=1 '初始化y
for y=1 to 255 'excel最多255列
if xlApp.Cells(x,y).Value = Ts Then '如果等于Ts
redim n(Ubound(n)+1) '重定义n数组元素个数为原个数+1
n(Ubound(n)-