2020-07-30 · 知道合伙人软件行家
用代码实现自动化,界面就是一个按钮,点一下就完成了工资表的计算,或者自动生成工资条等。
这就是操作界面。
Private Sub CommandButton3_Click() '检查填充
Dim skUArr(1 To 1000, 1 To 3)
Dim skUGs As Integer
Dim hH As Integer
Dim zlHH As Integer
Cells.Find(What:="Weight of box", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
zlHH = ActiveCell.Row '重量所在行号
skmGs = 0
hH = 5
Do While Trim(Cells(hH, 1).Text) <> ""
skUGs = skUGs + 1
skUArr(skUGs, 1) = Trim(Cells(hH, 1).Text)
skUArr(skUGs, 2) = Trim(Cells(hH, 4).Text)
skUArr(skUGs, 3) = Cells(hH, 10).Value
hH = hH + 1
Loop
Dim fName As String
Dim SBook As Workbook
Call SelectFile(fName)
Set SBook = Workbooks.Open(fName)
Dim M_sku As String, M_fnSku As String, M_qty As Integer
With SBook.Sheets(1)
For I = 1 To skUGs
M_sku = Trim(.Cells(5 + I - 1, 1).Text)
M_fnSku = Trim(.Cells(5 + I - 1, 4).Text)
M_qty = .Cells(5 + I - 1, 9).Value
If skUArr(I, 1) <> M_sku Then
MsgBox ("第" & I & "条记录的SKU不一致!")
Exit Sub
End If
If skUArr(I, 2) <> M_fnSku Then
MsgBox ("第" & I & "条记录的FNSKU不一致!")
Exit Sub
End If
If skUArr(I, 3) <> M_qty Then
MsgBox ("第" & I & "条记录的QTY不一致!")
Exit Sub
End If
Next I
End With
Dim qtyArr() As Integer
Dim boxGs As Integer
Dim boxArr()
With ThisWorkbook.Sheets(1)
boxGs = .Cells(4, 200).End(xlToLeft).Column
ReDim qtyArr(1 To skUGs, 1 To boxGs)
ReDim boxArr(1 To 4, 1 To boxGs)
'读取数量
For I = 1 To skUGs
For J = 1 To boxGs
qtyArr(I, J) = .Cells(5 + I - 1, 12 + J - 1).Value
Next J
Next I
'读取box
For I = 1 To 4
For J = 1 To boxGs
boxArr(I, J) = .Cells(zlHH + I - 1, 12 + J - 1).Value
Next J
Next I
End With
'填充
With SBook.Sheets(1)
'.Cells(5, 12).Resize(skUGs, boxGs) = qtyArr
'.Cells(zlHH, 12).Resize(4, boxGs) = boxArr
For I = 1 To skUGs
For J = 1 To boxGs
If qtyArr(I, J) > 0 Then
.Cells(5 + I - 1, 12 + J - 1) = qtyArr(I, J)
End If
Next J
Next I
For I = 1 To 4
For J = 1 To boxGs
.Cells(zlHH + I - 1, 12 + J - 1) = boxArr(I, J)
Next J
Next I
End With
SBook.Save
MsgBox ("检查结果OK,填充完成!")
End Sub
这是其中一个按钮的代码,供参考。
全是英文?看不懂?