|
楼主 |
发表于 2009-9-9 18:25
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub CommandButton1_Click()
[d2] = ""
[f2] = ""
[b3] = ""
[e3] = ""
[f3] = ""
CommandButton2.Enabled = True
If [b2] <> "" Then
Else
[b2] = VBA.Date
End If
orderno = "'" & Format([b2], "yyMM") & Format(GetOrderNo([b2]), "00000")
[d2] = orderno
End Sub
Function GetOrderNo(dte As Date) As Integer
Dim cnn As New Connection
Dim rs As New Recordset
Dim sqlstr As String
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & ThisWorkbook.FullName & ";Extended Properties=Excel 8.0"
.CursorLocation = adUseClient
.Open
End With
sqlstr = "select max(right([订单编号],5)) from [sheet2$a:f] where [订单日期]=#" & dte & "#"
rs.Open sqlstr, cnn
If Not rs.EOF And IsNull(rs.Fields(0)) = False Then
i = rs.Fields(0)
Else
i = 0
End If
GetOrderNo = i + 1
End Function
Private Sub CommandButton2_Click()
i = Sheet3.Range("a65536").End(xlUp).Row + 1
'MsgBox i
Sheet3.Range("a" & i) = [b2]
Sheet3.Range("b" & i) = [d2]
Sheet3.Range("c" & i) = [f2]
Sheet3.Range("d" & i) = [b3]
Sheet3.Range("e" & i) = [e3]
Sheet3.Range("f" & i) = [f3]
CommandButton2.Enabled = False
End Sub
Private Sub Worksheet_Activate()
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 5 Then
'MsgBox Target.Address
[b3] = Sheet2.Range("c:c").Find(Target.Value).Offset(0, -2).Value
'[e3] = Sheet2.Range("c:c").Find(Target.Value).Offset(0, -1).Value
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub |
|