今天介绍VB读取EXCEL表格,通过读取A列和B列的数据,进行判断,得出C列的数据

新建四个COMBO控件,和一个COMMAND控件,一个TEXT控件

打开FORM时,combo1控件显示EXCEL A列的所有数据,combo1控件显示EXCEL B列的所有数据,点击command1,TEXT1显示C列的数据;


代码如下:

Dim xlApp As Excel.Application '定义EXCEL类

Dim xlBook As Excel.Workbook '定义工件簿类

Dim xlsheet As Excel.Worksheet '定义工作表类

Dim TblMap_Card '创建一个变量

Private Sub Command1_Click()

Dim i As Integer

openEl

Tex = xl(1, 1)

Tex = xl(2, 1)

Tex = xl(3, 1)

End Sub

Private Sub openEl()

Dim myPath As String

myPath = "\book.xlsx"

Set xlApp = CreateObject("Excel.Application")

Set xlBook = xlA & myPath)

Set xlsheet = xlBook.Worksheets("sheet1")

'Set ekSheet = elBooks.Worksheets(1)

xlA = False

End Sub

Private Sub Command2_Click() '选择判断

For i = 1 To 18

If xl(i, 1) = Combo1.Text Then

If xl(i, 2) = Combo2.Text Then

Tex = xl(i, 3)

Exit Sub

End If

End If

Next i

End Sub

Private Sub Form_Load()

openEl

Combo1.AddItem "11"

Combo1.AddItem "22"

Combo1.AddItem "33"

Combo1.AddItem "44"

Combo1.AddItem "55"

Combo1.AddItem "66"

Combo2.AddItem "10"

Combo2.AddItem "20"

Combo2.AddItem "30"

End Sub

1.《(excel如何运行vb)Excel如何运行宏?》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《(excel如何运行vb)Excel如何运行宏?》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/keji/3299739.html