放上一个Excel里面的VBA,提醒自己不能再忘记 UsedRange 这个方法集了!
xvalue = -1
'这里读取sheet1里面的输入值
xvalue = Val(Sheet1.Cells("19", "A"))
If Trim(Sheet1.Cells("19", "A")) = "" Then
MsgBox "X 为空 "
Exit Sub
End If
xline = -1
For i = 6 To Sheet2.UsedRange.Rows.Count
If Val(Sheet2.Cells(i, "C")) = xvalue Then
xline = i
Exit For
End If
Next i
If xline = -1 Then
MsgBox "米找到"
Exit Sub
End If
Sheet1.Cells(23, 1) = Sheet2.Cells(xline, "J")
Sheet1.Cells(23, 2) = Sheet2.Cells(xline, "K")
Sheet1.Cells(23, 3) = Sheet2.Cells(xline, "M")
Sheet1.Cells(23, 4) = Sheet2.Cells(xline, "N")