VB操作EXCEL问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 20:26:29
比如sheet1表格中A列是我们单位的工号B列为我们单位员工名字

我现在要解决的问题是比如我在一个VB窗体上的文本框里填写103然后点击查找,那么能获取到表格中对应的"王五"这个值,而我查找110则是获取到"王菲"这个名字。

差不多和SQL查询功能一样(不知道能不能那么写)

注意千万不要给我回答那些指定读取行数又是单元格什么的,这些用不着你们来告诉我,我会。我现在要的是这种查找功能。

对我有帮助我就多给一些分,因为这里的分数我一点兴趣都没

可以这么写的啊!按照标准SQL来执行!
给你个例子!
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test.xls;Extended Properties=""Excel 8.0;HDR=Yes;"";"
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Set adoConn = New ADODB.Connection
adoConn.Open sConnString
Set adoRS = New ADODB.Recordset
adoRS.Open "select * from [sheet1$]", adoConn, 1, 3
Text1.Text = adoRS.Fields(0)
要是有什么不懂,直接HI我吧!

Private Sub CommandButton1_Click()
Dim tempint As Integer

Dim tempY As Integer
Dim tempflag As Boolean
Dim tempmsgbox As VbMsgBoxResult
tempflag = True

For tempY = 1 To 100
tempint = StrComp(TextBox1.Value, Cells(tempY, 1))
If (tempint = 0) Then
tempmsgbox = MsgBox(Cells(tempY, 2).Value & ":" & Cells(tempY, 1).Value, vbOKOnly, "查找在册员工")
tempflag = False
Else
End If
Next tempY