求助Excel VBA高手,请帮我把代码翻译成中文,告诉我此代码是什么意思!请详细一点!谢谢!

Sub 滞销商品筛选()
'获取用户输入
Dim choice As Integer
On Error GoTo esc
choice = InputBox("请输入需要清理的月份")
'新建一个工作表作为临时处理区域
Dim temp As Worksheet
Set temp = Worksheets.Add(after:=Worksheets(Worksheets.Count))
'拷贝原有区域
Worksheets(choice).Activate
Dim rownum As Integer
rownum = ActiveSheet.Range("A3").CurrentRegion.Rows.Count
ActiveSheet.Range(Cells(3, 1), Cells(rownum, 6)).Copy
'粘贴到临时工作表
temp.Activate
ActiveSheet.Paste
'按照名称排序
temp.Range(Cells(1, 1), Cells(rownum - 2, 6)).sort Key1:=Range("A1")
'查找应该下架的货品名称
Dim goodname(100) As String
Dim index As Integer
index = 1
For i = 2 To rownum - 2
If (Cells(i, 1) = Cells(i - 1, 1)) And _
(Cells(i, 5) - Cells(i - 1, 5) > 20) And _
(Cells(i, 1) <> goodname(index - 1)) Then
goodname(index) = Cells(i, 1)
index = index + 1
End If
Next i
'将货品名称拼接为列表
Dim result As String
For i = 1 To index - 1
result = result & goodname(i) & Chr(10)
Next i
'显示结果
MsgBox choice & "月份20天内没有售出的货品清单如下:" & Chr(10) & result
'删除临时工作表
Application.DisplayAlerts = False
temp.Delete
'将原表中的对应记录标示出来
Worksheets(choice).Activate
For i = 3 To rownum - 2
For j = 1 To index - 1
If Cells(i, 1) = goodname(j) Then
Cells(i, 7).value = "滞销"
Cells(i, 7).Font.ColorIndex = 3
End If
Next j
Next i
esc: Exit Sub
End Sub

Sub 滞销商品筛选()
'获取用户输入
Dim choice As Integer '定义变量
On Error GoTo esc '错误则返回esc标签
choice = InputBox("请输入需要清理的月份") '请求用户输入框
'新建一个工作表作为临时处理区域
Dim temp As Worksheet '定义变量
Set temp = Worksheets.Add(after:=Worksheets(Worksheets.Count)) '新建表放在最后面
'拷贝原有区域
Worksheets(choice).Activate '激活表
Dim rownum As Integer '定义变量
rownum = ActiveSheet.Range("A3").CurrentRegion.Rows.Count '将A3当前区域行总数赋给变量
ActiveSheet.Range(Cells(3, 1), Cells(rownum, 6)).Copy '活动工作表指定单元格复制
'粘贴到临时工作表
temp.Activate
ActiveSheet.Paste '粘贴
'按照名称排序
temp.Range(Cells(1, 1), Cells(rownum - 2, 6)).sort Key1:=Range("A1") '以A1单元格为条件排序
'查找应该下架的货品名称
Dim goodname(100) As String '定义变量
Dim index As Integer '定义变量
index = 1 '变量赋值
For i = 2 To rownum - 2 '循环赋值
If (Cells(i, 1) = Cells(i - 1, 1)) And _ '条件
(Cells(i, 5) - Cells(i - 1, 5) > 20) And _
(Cells(i, 1) <> goodname(index - 1)) Then
goodname(index) = Cells(i, 1) '满足条件执行的代码
index = index + 1
End If '结束条件语句
Next i '结束循环
'将货品名称拼接为列表
Dim result As String
For i = 1 To index - 1
result = result & goodname(i) & Chr(10)
Next i
'显示结果
MsgBox choice & "月份20天内没有售出的货品清单如下:" & Chr(10) & result '显示提示框
'删除临时工作表
Application.DisplayAlerts = False '删除表不提示
temp.Delete '删除表
'将原表中的对应记录标示出来
Worksheets(choice).Activate '激活表
For i = 3 To rownum - 2 '循环
For j = 1 To index - 1
If Cells(i, 1) = goodname(j) Then '条件
Cells(i, 7).value = "滞销" '满足条件执行语句
Cells(i, 7).Font.ColorIndex = 3 '设置单元格字体颜色
End If
Next j
Next i
esc: Exit Sub '标签下的代码"退出过程"
End Sub 过程结束
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-07-03
有中文注释
相似回答