本帖最後由 wiemanson 於 2010-7-22 17:40 編輯
各位前輩好!
我寫了一個程式,然後活頁簿的資料則是我自己先亂輸入拿來測試程式是否順利用的,就在我終於成功順利執行後,匯入正式要算的資料進去活頁簿,居然就無法執行了!
不知道是出了什麼問題,後來我就在用我原本測試的活頁簿資料在去執行,結果又可以執行,然後我就一直試到底是哪裡出了問題,結果發現只要我刪除那測試用的活頁簿資料,就會跑出沒有設定物件變數或WITH區塊變數的錯誤視窗!
我的程式是寫在THISBOOK裡面,程式碼如下所示
Sub s1()
Worksheets("Sheet1").Select
x = 1
Do
If Cells(x, 1) = "" Then Exit Do
ElseIf Cells(x, 1) = Cells.Find(What:="林", After:=ActiveCell) And Cells(x, 3) = Cells.Find(What:="4", After:=ActiveCell) And Cells(x, 4) = "普通" And Cells(x, 6) = "否" Then
Cells(x, 7) = 23 * Cells(x, 5)
ElseIf Cells(x, 1) = Cells.Find(What:="林", After:=ActiveCell) And Cells(x, 4) = "好" And Cells(x, 6) = "否" Then
Cells(x, 7) = 20 * Cells(x, 5)
ElseIf Cells(x, 1) = Cells.Find(What:="林", After:=ActiveCell) And Cells(x, 4) = "不好" And Cells(x, 5) <= 20 And Cells(x, 6) = "否" Then
Cells(x, 7) = 300
ElseIf Cells(x, 1) = Cells.Find(What:="林", After:=ActiveCell) And Cells(x, 6) = "否" And Cells(x, 4) = "其它" Then
Cells(x, 7) = "另外算"
ElseIf Cells(x, 1) = Cells.Find(What:="力", After:=ActiveCell) And Cells(x, 4) = "好" And Cells(x, 6) = "否" Then
Cells(x, 7) = 10 * Cells(x, 5)
ElseIf Cells(x, 1) = Cells.Find(What:="力", After:=ActiveCell) And Cells(x, 4) = "不好" And Cells(x, 6) = "否" Then
Cells(x, 7) = 2 * Cells(x, 5)
ElseIf Cells(x, 1) = Cells.Find(What:="力", After:=ActiveCell) And Cells(x, 4) = "普通" And Cells(x, 5) <= 20 And Cells(x, 6) = "否" Then
Cells(x, 7) = 300
ElseIf Cells(x, 1) = Cells.Find(What:="力", After:=ActiveCell) And Cells(x, 6) = "否" And Cells(x, 4) = "其它" Then
Cells(x, 7) = "另外算"
End If
x = x + 1
Loop
End Sub
我也爬文爬了很久,試過了把程式碼寫在模組裡面,結果也不行!
請問我要怎麼解決這問題呢!?
請各位前輩指導迷津!
謝謝! |