
Public Sub 客户正常供价批量维护()
If Cells(4, 6) = "" Then
MsgBox "请先选择需要维护价格的系统!", vbInformation
Cells(4, 6).Select
Exit Sub
Else
Dim i As Integer, j As Integer, k As Integer, sht As Worksheet 'i,j,k为整数变量;sht 为excel工作表对象变量,指向某一工作表
Dim cn As New ADODB.Connection '定义数据链接对象 ,保存连接数据库信息;请先添加ADO引用
Dim rs As New ADODB.Recordset '定义记录集对象,保存数据表
Dim strCn As String, strSQL As String '字符串变量
Dim mdbFile As String
On Error GoTo add_err
mdbFile = ActiveWorkbook.Path &"\DY_DATA.mdb"
strCn = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &mdbFile '定义数据库链接字符串
cn.Open strCn '与数据库建立连接,如果成功,返回连接对象cn
Set rs = New ADODB.Recordset
rs.Open "dbl直营客户正常供价表", cn, adOpenKeyset, adLockOptimistic
k = Cells(4, 8) + 8
For i = 9 To k
If Cells(i, 7) = "" Then
Else
rs.AddNew
rs(1) = Cells(i, 2)
rs(2) = Cells(i, 7)
rs(3) = Cells(i, 8)
rs.Update
Cells(i, 7) = ""
Cells(i, 8) = ""
End If
Next
MsgBox "数据记录添加成功!", vbInformation
Cells(4, 6).Select
ActiveWorkbook.RefreshAll
add_exit:
Exit Sub
End If
add_err:
MsgBox Err() &vbCrLf &Error()
Resume add_exit
End Sub
i = 2Do While Cells(i, 1) <>""
i = i + 1
Loop
Cells(i, 1) = "填入内容"
Cells(i, 2) = "填入内容"
Cells(i, 3) = "填入内容"
原理:找到第一列最后空白的单元格作为输入数据行
Private Sub CommandButton1_Click()Dim x
For x = 1 To 2
ListBox1.AddItem x
Next x
End Sub
Private Sub CommandButton2_Click()
Dim Y
For Y = 0 To 1
If ListBox1.Selected(Y) = True Then ' '判断是否选中
'ListBox1.RemoveItem (Y) '判断是否选中,如果是就移出它
'ListBox1.List(Y) = "" '这句相当于在删出的地方增加了一行;
ListBox1.AddItem "123", Y '选中的地方加一行,输入值为123.
End If
Next Y
End Sub
1、删除选中记录可以用Selected语句判断;
2、选中处插入一行可以用 ListBox1.AddItem "123", Y
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)