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

Private Sub CommandButton1_Click()
Dim i As Long, u As Long, p As Long
Dim j As Integer, t, q, LL As Integer
Dim bh As String
Dim JUDGE As String
Dim STP As Integer
'编号
If Range("m6") = "" Then
bh = Format(Now, "yyyymmdd") & "001"
Range("m6") = bh
End If
'编号
If Format(Now, "yyyymmdd") = Left(Cells(6, 12), 8) Then
bh = Format(Now, "yyyymmdd") & Right("000000" & CStr(CInt(Right(Cells(6, 12), 3)) + 1), 3)
Range("m6") = bh
Else
bh = Format(Now, "yyyymmdd") & "001"
Cells(6, 12) = bh
End If

If Range("S3").Value = 2 Then
If Cells(7, 5).Value = "" Then
MsgBox "领用单位不能为空。", vbOKOnly, "友情提示!!!"
Cells(7, 5).Select
Exit Sub
End If
End If

i = 9

Do Until Len(Range("F" & i).Text) = 0
If Cells(i, 4).Value = "" Then
MsgBox "日期不能为空。", vbOKOnly, "友情提示!!!"
Cells(i, 4).Select
Exit Sub
End If
If Cells(i, 9).Value = "" Then
MsgBox "数量不能为空。", vbOKOnly, "友情提示!!!"
Cells(i, 9).Select
Exit Sub
End If

i = i + 1
Loop

If Cells(9, 4).Value <> "" Then

If Range("s3") = 1 Then
JUDGE = "入库清单"
STP = 16
Else
JUDGE = "出库清单"
STP = 31
End If

Sheets(JUDGE).Select
ActiveSheet.Unprotect

i = Val(Sheets(JUDGE).Range("b65536").End(xlUp).Row)
u = Val(Sheets("单据录入").Range("T3").Value)
p = Val(Sheets("单据录入").Range("U3").Value)

For t = 1 To p

For j = 1 To u + 1

Sheets(JUDGE).Cells(i + t, j).Value = Sheets("单据录入").Cells(8 + t, j + STP - 1).Value

Next j
Next t

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

Sheets("单据录入").Select

'ActiveWorkbook.Save '保存
MsgBox "保存成功", vbOKOnly

ActiveSheet.Unprotect
Range("E7,H7,K7,M6,D9:E15,E15,i9:i15,l9:l15,N9:N15").Select

Selection.ClearContents
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If

Range("E7").Select

End Sub

Private Sub CommandButton1_Click() '私有的子程序 CommandButton1_<点击>()
Dim i As Long, u As Long, p As Long '定义变量 i 为 长整型值,u 为 长整型值,p 为 长整型值
Dim j As Integer, t, q, LL As Integer '定义变量 j 为 整型值,t,q,LL 为 整型值
Dim bh As String '定义变量 bh 为 字符串
Dim JUDGE As String '定义变量 JUDGE 为 字符串
Dim STP As Integer '定义变量 STP 为 整型值
'编号
If Range("m6") = "" Then '如果 <单元格>区域("m6")=空值 则执行
bh = Format(Now, "yyyymmdd") & "001" ' bh=Format(当前时间,"yyyymmdd") & "001"
Range("m6") = bh '<单元格>区域("m6")= bh
End If 'If判断过程结束
'编号
If Format(Now, "yyyymmdd") = Left(Cells(6, 12), 8) Then '如果 Format(当前时间,"yyyymmdd")=<截取字符串左侧>(<单元格>坐标(6,12),8) 则执行
bh = Format(Now, "yyyymmdd") & Right("000000" & CStr(CInt(Right(Cells(6, 12), 3)) + 1), 3) ' bh=Format(当前时间,"yyyymmdd") & 截取字符串右侧("000000" & CStr(CInt(截取字符串右侧(<单元格>坐标(6,12),3))+1),3)
Range("m6") = bh '<单元格>区域("m6")= bh
Else '另外
bh = Format(Now, "yyyymmdd") & "001" ' bh=Format(当前时间,"yyyymmdd") & "001"
Cells(6, 12) = bh '<单元格>坐标(6,12)= bh
End If 'If判断过程结束
If Range("S3").Value = 2 Then '如果 <单元格>区域("S3" )的值=2 则执行
If Cells(7, 5).Value = "" Then '如果 <单元格>坐标(7,5 )的值=空值 则执行
MsgBox "领用单位不能为空。", vbOKOnly, "友情提示!!!" '<消息框>:"领用单位不能为空。",vbOKOnly,"友情提示!!!"
Cells(7, 5).Select '<单元格>坐标(7,5 )的选定
Exit Sub '退出子程序
End If 'If判断过程结束
End If 'If判断过程结束
i = 9 'i=9
Do Until Len(Range("F" & i).Text) = 0 '执行循环操作 直到<字符串长度值>(<单元格>区域("F" & i )的文本)=0
If Cells(i, 4).Value = "" Then '如果 <单元格>坐标(i,4 )的值=空值 则执行
MsgBox "日期不能为空。", vbOKOnly, "友情提示!!!" '<消息框>:"日期不能为空。",vbOKOnly,"友情提示!!!"
Cells(i, 4).Select '<单元格>坐标(i,4 )的选定
Exit Sub '退出子程序
End If 'If判断过程结束
If Cells(i, 9).Value = "" Then '如果 <单元格>坐标(i,9 )的值=空值 则执行
MsgBox "数量不能为空。", vbOKOnly, "友情提示!!!" '<消息框>:"数量不能为空。",vbOKOnly,"友情提示!!!"
Cells(i, 9).Select '<单元格>坐标(i,9 )的选定
Exit Sub '退出子程序
End If 'If判断过程结束
i = i + 1 'i=i+1
Loop '循环执行
If Cells(9, 4).Value <> "" Then '如果 <单元格>坐标(9,4 )的值 不等于 空值 则执行
If Range("s3") = 1 Then '如果 <单元格>区域("s3")=1 则执行
JUDGE = "入库清单" 'JUDGE="入库清单"
STP = 16 'STP=16
Else '另外
JUDGE = "出库清单" 'JUDGE="出库清单"
STP = 31 'STP=31
End If 'If判断过程结束
Sheets(JUDGE).Select '<工作表>(JUDGE )的选定
ActiveSheet.Unprotect ' 活动工作表的取消保护
i = Val(Sheets(JUDGE).Range("b65536").End(xlUp).Row) 'i=<提取数字>(<工作表>(JUDGE )的<单元格>区域("b65536" )的<末端>(方向向上 )的行标)
u = Val(Sheets("单据录入").Range("T3").Value) 'u=<提取数字>(<工作表>("单据录入" )的<单元格>区域("T3" )的值)
p = Val(Sheets("单据录入").Range("U3").Value) 'p=<提取数字>(<工作表>("单据录入" )的<单元格>区域("U3" )的值)
For t = 1 To p '设定变量范围为t=1到p
For j = 1 To u + 1 '设定变量范围为j=1到u+1
Sheets(JUDGE).Cells(i + t, j).Value = Sheets("单据录入").Cells(8 + t, j + STP - 1).Value '<工作表>(JUDGE )的<单元格>坐标(i+t,j )的值=<工作表>("单据录入" )的<单元格>坐标(8+t,j+STP-1 )的值
Next j '下一个j
Next t '下一个t
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True ' 活动工作表的保护保护图形=True,内容=True,方案=True
Sheets("单据录入").Select '<工作表>("单据录入" )的选定
'ActiveWorkbook.Save '保存
MsgBox "保存成功", vbOKOnly '<消息框>:"保存成功",vbOKOnly
ActiveSheet.Unprotect ' 活动工作表的取消保护
Range("E7,H7,K7,M6,D9:E15,E15,i9:i15,l9:l15,N9:N15").Select '<单元格>区域("E7,H7,K7,M6,D9:E15,E15,i9:i15,l9:l15,N9:N15" )的选定
Selection.ClearContents ' 被选项的清除内容
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True ' 活动工作表的保护保护图形=True,内容=True,方案=True
End If 'If判断过程结束
Range("E7").Select '<单元格>区域("E7" )的选定
End Sub '子程序结束
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-02-24
'强制声明
Option Explicit
'单元格更改时触发事件
Private Sub Worksheet_Change(ByVal Target As Range)
'如果活动单元格大于1时停止程序
If Target.Count > 1 Then Exit Sub
'使用Intersect方法判断所选单元格
If Intersect([b2].CurrentRegion, Target) Is Nothing Then Exit Sub
'声明变量
Dim yf$, r1, rq, c%, ad$
'将B2单元格的值赋值给变量yf
yf = [b2].Value
'将活动单元格的位置赋值给变量ad
ad = Target.Address
'将活动单元格所在的列号减7后赋值给变量c
c = Target.Column - 7
'将获取的单元格值赋值给变量rq
rq = Target.Offset(0, -c)
'使用Find方法在49行至504行单元格区域内查找
Set r1 = Rows("49:504").Find(rq, , , 1)
'如果找到
If Not r1 Is Nothing Then
'写入当前活动单元格的值
Cells(r1.Row, r1.Column).Offset(0, c) = Target.Value
End If
End Sub
'单元格激活时触发事件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'如果活动单元格大于2时停止程序
If Target.Count > 2 Then Exit Sub
'使用Intersect方法判断所选单元格
If Intersect([a1:m1], Target) Is Nothing Then Exit Sub
'声明变量
Dim yf$, r1, rng As Range
'将活动单元格的位置赋值给变量yf
yf = Target.Value
'使用Find方法在49行至504行单元格区域内查找
Set r1 = Rows("49:504").Find(yf, , , 1)
'如果找到
If Not r1 Is Nothing Then
'赋值给变量rng
Set rng = Range(r1.Address).CurrentRegion
'将变量rng 的值复制到B2单元格
rng.Copy [b2]
End If
End Sub

参考资料:百度一下

相似回答