|
楼主 |
发表于 2002-1-31 10:41
|
显示全部楼层
对不起, 每个命令按钮的代码不是完全相同.只是有一定的规律.与参数i有关.我的代码如下:
Sub copyclear(i As Integer)
Dim an, bn As Integer
Dim range1, range2, range3 As String
Range("A3:AZ25").Select
Selection.copy
an = 3 + 23 * i
bn = 25 + 23 * i
range1 = "A" + Format(an) + ":" + "AZ" + Format(bn)
Range(range1).Select
ActiveSheet.Paste
an = 5 + 23 * i
bn = 12 + 23 * i
range2 = "A" + Format(an) + ":" + "AZ" + Format(bn)
Range(range2).Select
Selection.ClearContents
Application.CutCopyMode = False
an = 15 + 23 * i
bn = 24 + 23 * i
range3 = "D" + Format(an) + ":" + "AZ" + Format(bn)
Range(range3).Select
Application.CutCopyMode = False
Selection.ClearContents
Sheet1.CommandButton1.copy
an = 13 + 23 * i
bn = 14 + 23 * i
range4 = "B" + Format(an) + ":" + "C" + Format(bn)
Range(range4).Select
ActiveSheet.Paste
Dim MyCodeLine(3) As String
MyCodeLine(1) = "Private Sub CommandButton(i as integer)"
MyCodeLine(2) = " an = 13 + 23 * i" ‘ 这一行我不理解
MyCodeLine(3) = "End Sub"
For i = 1 To 3
Application.VBE.CodePanes(1).CodeModule.InsertLines i, MyCodeLine(i)
Next
End Sub
Sub CommandButton(i As Integer)
Dim begin_date As Date
Dim myrange, range1, range2, range3 As Range, myfind As Range
Dim aa, bb, an, bn, cn, dn, en, fn As Integer
If CommandButton1.Locked = False Then
begin_date = Date
an = 13 + 23 * i
Cells(an, 4) = begin_date
Set myrange = ActiveSheet.Rows(an)
bn = 3 + 23 * i
range1 = "F" + Format(bn)
Set myfind = myrange.Find(what:=Range(range1).Value, LookIn:=xlValues, MatchCase:=False)
If Not myfind Is Nothing Then
mycolumn = myfind.Column
aa = mycolumn '预交日所在栏
End If
'------装配排程
bb = Int(Cells(bn, 10)) '预计工作日取整
cc = Cells(bn, 13) - 1 '与预交日相隔的天数
dd = Cells(bn, 11) '预计工作日
cn = 23 + 23 * i
If cc >= dd Then
Do Until bb = 0
Cells(cn, aa - dd) = Cells(bn, 8)
bb = bb - 1
dd = dd - 1
Loop
Cells(cn, aa - dd) = Cells(bn, 4) - Cells(bn, 8) * Int(Cells(bn, 10))
Else
bb = Int(Cells(bn, 10))
dd = 5
Do Until bb = 0
Cells(cn, dd) = Cells(bn, 8)
bb = bb - 1
dd = dd + 1
Loop
MsgBox "注意:你必须要按排加班时间!"
Cells(an, mycolumn - 1).Interior.ColorIndex = 3
Cells(cn, mycolumn - 1) = Cells(cn, mycolumn - 1) + (Cells(bn, 4) - Cells(bn, 8) * Int(Cells(bn, 10)))
End If
'------黑身排程
dn = 21 + 23 * i
If Cells(dn, 2) <> 0 Then '若有托外情况
For i = 1 To 4
bb = Int(Cells(bn, 10)) '预计工作日取整
cc = Cells(bn, 13) - 1 '与预交日相隔的天数
dd = Cells(bn, 11) '预计工作日
If cc - i >= dd Then
Do Until bb = 0
Cells(cn - 2 * i, aa - dd - i) = Cells(bn, 8)
bb = bb - 1
dd = dd - 1
Loop
Cells(cn - 2 * i, aa - dd - i) = Cells(bn, 4) - Cells(bn, 8) * Int(Cells(bn, 10))
Else
bb = Int(Cells(bn, 10))
dd = 5
Do Until bb = 0
Cells(cn - 2 * i, dd) = Cells(bn, 8)
bb = bb - 1
dd = dd + 1
Loop
MsgBox "注意:你必须要按排加班时间!"
Cells(an, mycolumn - 1 - i).Interior.ColorIndex = 3
Cells(cn - 2 * i, mycolumn - 1 - i) = Cells(cn - 2 * i, mycolumn - 1 - i) + (Cells(bn, 4) - Cells(bn, 8) * Int(Cells(bn, 10)))
End If
Next i
Else '若没有托外
For i = 1 To 3
bb = Int(Cells(bn, 10)) '预计工作日取整
cc = Cells(bn, 13) - 1 '与预交日相隔的天数
dd = Cells(bn, 11) '预计工作日
If cc - i >= dd Then
Do Until bb = 0
Cells(dn - 2 * i, aa - dd - i) = Cells(bn, 8)
bb = bb - 1
dd = dd - 1
Loop
Cells(dn - 2 * i, aa - dd - i) = Cells(bn, 4) - Cells(bn, 8) * Int(Cells(bn, 10))
Else
bb = Int(Cells(bn, 10))
dd = 5
Do Until bb = 0
Cells(dn - 2 * i, dd) = Cells(bn, 8)
bb = bb - 1
dd = dd + 1
Loop
MsgBox "注意:你必须要按排加班时间!"
Cells(an, mycolumn - 1 - i).Interior.ColorIndex = 3
Cells(dn - 2 * i, mycolumn - 1 - i) = Cells(dn - 2 * i, mycolumn - 1 - i) + (Cells(bn, 4) - Cells(bn, 8) * Int(Cells(bn, 10)))
End If
Next i
End If
CommandButton1.Locked = True
Else
Dim response
response = MsgBox("已经排程!需重新排程吗?", vbYesNo)
If response = vbYes Then
CommandButton1.Locked = False
en = 15 + 23 * i
fn = 24 + 23 * i
range2 = "D" + Format(en) + ":" + "AZ" + Format(fn)
range3 = "D" + Format(an) + ":" + "AZ" + Format(an)
Range(range2).ClearContents
Range(range3).Interior.ColorIndex = 2
MsgBox "请再按一次!"
End If
End If
End Sub |
|