Home > Software engineering >  VBA to data form, to fill in the combobox
VBA to data form, to fill in the combobox

Time:10-05

Excel data is as follows:
Province number
Hubei S01
Yunnan S01
Hunan S01
Hubei S02
Beijing S03
Shanghai S04
Jiangsu S04
Hubei S04

Use the following code, province information can be filled into the combobox1
 Sub fillcombox () 

Dim CNN As New Connection
Dim the rs As New you
Dim mybook As String, Sql As String
Mybook=ThisWorkbook. FullName 'will make workbook name
With CNN
. The Provider="Microsoft jet. The oledb. 4.0"
. The ConnectionString="Extended properties=" excel "8.0; HDR=YES." "; Data source="& amp; Mybook
. Open
End With
Sql="from the select Distinct provinces [Sheet1 $A1: B9]"
Rs. The Open Sql, CNN, adOpenStatic
With Sheet1.Com boBox1
. The Clear
Do
AddItem rs! Province
Rs. MoveNext
EOF
Loop Until the rs.End With
End Sub

CodePudding user response:

The building Lord what problem?

Vba in excel database is used to operate, and take off pants break wind,
  •  Tags:  
  • VBA
  • Related