- 帖子
- 14
- 主題
- 5
- 精華
- 0
- 積分
- 21
- 點名
- 0
- 作業系統
- Windows XP
- 軟體版本
- SP3
- 閱讀權限
- 10
- 註冊時間
- 2011-3-9
- 最後登錄
- 2021-10-26
|
各位好
我的程式有階段錯誤''91''的問題,但我實在找不出來原因,
只好上來求教了。
程式碼如下:
Sub Scheduling()
With Worksheets("Scheduling")
n = .Columns("A").Find("*", SearchOrder:=xlByRows, LookIn:=xlFormulas, SearchDirection:=xlPrevious).EntireRow.Row
For i = 5 To n Step 2
ProductID = Worksheets("Scheduling").Cells(i, 3)
Set d = Sheets("KEYIN").Columns("AH").Find(ProductID, LookIn:=xlValues, lookat:=xlWhole) '在資料庫中搜尋相等 料號 之值
If Not d Is Nothing Then ' 如果找到相等之值的話
Product = Worksheets("KEYIN").Cells(d.Row, d.Column + 1)
End If
.Cells(i, 4) = Product
Next i
End With
Worksheets("M").Activate
For i = 3 To 23
For Each od In ActiveSheet.Buttons
If od.Name = ("Buttons " & i) Then
od.Delete
End If
Next
For Each od In ActiveSheet.OLEObjects
If od.Name = ("CheckBox" & CStr(i)) Or od.Name = ("CheckBoxb" & CStr(i)) Then
od.Delete
End If
Next
serial = 0
machine = Worksheets("M").Cells(i, 3)
Set c = Worksheets("Scheduling").Columns("B").Find(machine, LookIn:=xlValues, lookat:=xlWhole) '在資料庫中搜尋相等 之值
If Not c Is Nothing Then ' 如果找到相等之值的話
firstAddress = c.Address
serial = 1
Do
If Worksheets("Scheduling").Cells(c.Row, 1) = Date And serial = 1 Then
ProductID = Worksheets("Scheduling").Cells(c.Row, 3)
Product = Worksheets("Scheduling").Cells(c.Row, 4)
Demand = Worksheets("Scheduling").Cells(c.Row, 5)
Operater = Worksheets("Scheduling").Cells(c.Row, 7)
Starttime = Worksheets("Scheduling").Cells(c.Row, 9)
Worksheets("Scheduling").Cells(c.Row, 11) = 1
Range(Worksheets("Scheduling").Cells(c.Row, 1), Worksheets("Scheduling").Cells(c.Row + 1, 9)).ClearContents
Worksheets("M").Cells(i, 4) = Product
Worksheets("M").Cells(i, 5) = Demand
Worksheets("M").Cells(i, 7) = Operater
Worksheets("M").Cells(i, 12) = Starttime
If Operater > 0 Then
SS = Worksheets("M").Cells(i, 1).Top '所選擇的目標位址
ll = Worksheets("M").Cells(i, 1).Left
Set ob = Worksheets("M").Buttons.Add(ll + 940, SS + 6, 33, 19) '加入按鈕
ob.Characters.Text = "完成" '指定按鈕文字
ob.OnAction = "scheduleok" '指定按鈕巨集
ob.Name = "Buttons " & i '指定按鈕名稱
S = Worksheets("M").Cells(i, 7).Top '所選擇的目標位址
l = Worksheets("M").Cells(i, 7).Left
Set ob1 = Worksheets("M").OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=l, Top:=S + 1, Width:=26, Height:=13)
ob1.Name = "CheckBox" & i
ob1.Object.Caption = "日"
ob1.Object.Font.Size = 9
ob1.Object.ForeColor = RGB(255, 128, 128)
'ob1.Object.AutoSize = True
ob1.Object.BackColor = Worksheets("M").Cells(i, 7).Interior.Color
'ob1.Object.SpecialEffect = 0
End If
ElseIf Worksheets("Scheduling").Cells(c.Row, 1) = Date And serial = 2 Then
ProductID = Worksheets("Scheduling").Cells(c.Row, 3)
Product = Worksheets("Scheduling").Cells(c.Row, 4)
Worksheets("M").Cells(i, 13) = Product
End If
serial = 2
Set c = Worksheets("Scheduling").Columns("B").FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
Next i
End Sub
還請各位高手們相助! |
|