|
有一个调拨工具实现了二个单元格A和B都是数值 (一个做减法 一个做加法),然后自动获取减少的单元格信息做调出,自动获取调入信息,并记录同行的其他信息,一个朋友写的代码不太看的懂请大神指教,最好能写个注释,必有感谢!
Sub Worksheet_SelectionChange(ByVal Target As Range)
Rem 090215加入。在透视表中修改数据进行调配,在工作表124中自动记录调配!
Rem 透视表格式:A列放季节,B列放编码,C列放货号,第1行放门店,库存区域从D2单元格开始
Dim i As Long
Dim j As Integer
Static r1 As Integer
Static r2 As Integer
Static c1 As Integer
Static c2 As Integer
Static value As Variant
Static jijie As String
Static chima As String
Static huohao As String
Static dalei As String
Static zhonglei As String
Static pinming As String
Static pinlei As String
Static gushibao As String
Static xingbie As String
Static tiaochu As String
Static tiaoru As String
Static zeng As Integer
Static jian As Integer
Static hs As Integer
Static flag As Boolean
On Error Resume Next
If Range("IQ2103") = "" Then
If flag = True Then Application.StatusBar = "就绪"
If r1 = 0 Then
hs = 1
Sheets("124").Cells(1, 1) = "季节"
Sheets("124").Cells(1, 2) = "货号"
Sheets("124").Cells(1, 3) = "尺码"
Sheets("124").Cells(1, 4) = "大类"
Sheets("124").Cells(1, 5) = "中类"
Sheets("124").Cells(1, 6) = "品名"
Sheets("124").Cells(1, 7) = "品类"
Sheets("124").Cells(1, 8) = "故事包"
Sheets("124").Cells(1, 9) = "性别 "
Sheets("124").Cells(1, 10) = "数量"
Sheets("124").Cells(1, 11) = "调出"
Sheets("124").Cells(1, 12) = "调入"
r1 = ActiveCell.Row
c1 = ActiveCell.Column
value = ActiveCell.value
If MsgBox("使用说明:保证有一个名为124的工作表!如果没有,请点击“否”," & vbCrLf & "并新建一个名为124的工作表,然后退出Excel文件,重新打开后即可使用!", vbYesNo, "方法") = vbNo Then
Exit Sub
End If
End If
Rem 如果上一个单元格的内容发生改变
If Cells(r1, c1) <> value Then
If Cells(r1, c1) < value Then
Cells(r1, c1).Interior.ColorIndex = 4
r2 = r1
c2 = c1
jian = value - Cells(r1, c1)
tiaochu = Cells(1, c1)
jijie = Cells(r1, 1)
huohao = Cells(r1, 2)
chima = Cells(r1, 3)
dalei = Cells(r1, 4)
zhonglei = Cells(r1, 5)
pinming = Cells(r1, 6)
pinlei = Cells(r1, 7)
gushibao = Cells(r1, 8)
xingbie = Cells(r1, 9)
Sheets("124").Cells(1, 107) = jijie
Sheets("124").Cells(1, 108) = huohao
Sheets("124").Cells(1, 109) = chima
Sheets("124").Cells(1, 110) = jian
Sheets("124").Cells(1, 111) = tiaochu
Sheets("124").Cells(1, 112) = r1
Application.StatusBar = "货号:" & huohao & ",数量:" & jian & ",计划调出门店:" & tiaochu
flag = False
End If
If Cells(r1, c1) >= value Then
zeng = Cells(r1, c1) - value
tiaoru = Cells(1, c1)
If Sheets("124").Cells(1, 110) <> zeng Or Sheets("124").Cells(1, 112) <> r1 Then
MsgBox "增减量不同!或不是同一个货号!", vbOKOnly, "出错了!!"
Cells(r2, c2).Interior.ColorIndex = Cells(r2, c2 - 1).Interior.ColorIndex
Cells(r2, c2) = Cells(r2, c2) + jian
Cells(r1, c1) = Cells(r1, c1) - zeng
Application.StatusBar = "就绪"
If Cells(r1, c1) = 0 Then Cells(r1, c1) = ""
zeng = 0
jian = 0
r1 = 0
c1 = 0
r2 = 0
c2 = 0
Else
Cells(r1, c1).Interior.ColorIndex = 3
For i = 2 To 65530
If Sheets("124").Cells(i, 1) = "" Then
For j = 1 To 11 Step 2
Sheets("124").Cells(1, (j + 1) / 2) = Mid("季节货号尺码大类中类品名调出调入", j, 2)
Next j
Sheets("124").Cells(i, 1) = jijie
Sheets("124").Cells(i, 2) = huohao
Sheets("124").Cells(i, 3) = chima
Sheets("124").Cells(i, 4) = dalei
Sheets("124").Cells(i, 5) = zhonglei
Sheets("124").Cells(i, 6) = pinming
Sheets("124").Cells(i, 7) = pinlei
Sheets("124").Cells(i, 8) = gushibao
Sheets("124").Cells(i, 9) = xingbie
Sheets("124").Cells(i, 10) = zeng
Sheets("124").Cells(i, 11) = tiaochu
Sheets("124").Cells(i, 12) = tiaoru
Application.StatusBar = "货号:" & huohao & ",数量:" & jian & ",调出门店:" & tiaochu & ",调入门店:" & tiaoru & " 调配被成功记录!"
flag = True
zeng = 0
jian = 0
r1 = 0
c1 = 0
r2 = 0
c2 = 0
Exit For
End If
Next i
End If
End If
End If
r1 = ActiveCell.Row
c1 = ActiveCell.Column
value = ActiveCell.value
End If
End Sub
|
|