- 帖子
- 835
- 主題
- 6
- 精華
- 0
- 積分
- 915
- 點名
- 0
- 作業系統
- Win 10,7
- 軟體版本
- 2019,2013,2003
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2010-5-3
- 最後登錄
- 2024-11-14
|
2#
發表於 2014-11-20 04:05
| 只看該作者
各位前輩好
請問這段語法 紅字部份哪邊撰寫錯誤 他一直出現型態不符和
紅字部份 我要寫入的條件式是 ...
alex520188 發表於 2014-11-19 10:51 
紅字是指 For Each current In Worksheets 這一行嗎?
我執行起來沒問題喔.- Sub 鋼筋計()
-
- Dim I%, J%, k% '宣告變數
- Dim current As Worksheet
- For Each current In Worksheets '對所有活頁簿作處理
- current.Select
- J = 1
- Do While Cells(1, J) <> "量測值" '滿足條件時執行以下動作
- J = J + 1
- Loop
- J = J - 1
- Columns(J).Insert Shift:=xlToRight '向右插入一欄
- k = Range("a:a").End(xlDown).Row '取得A欄最後一格有資料的值
- Range(Columns(J + 1).Rows(2), Columns(J + 2).Rows(k)).Clear '欄位數值清除
- Cells(1, J) = Now() '鍵入時間
- For I = 2 To k Step 1
- If Cells(I, (J - 1)) - Cells(I, (J - 2)) > 0 Then
- Randomize '若相減大於0 跑負亂數
- Cells(I, J) = Round(((-1 - -3) * Rnd + -3), 1) + Cells(I, (J - 1))
- ElseIf Cells(I, (J - 1)) - Cells(I, (J - 2)) < 0 Then
- Randomize '若相減小於0 跑正亂數
- Cells(I, J) = Round(((2 - 1) * Rnd + 1), 1) + Cells(I, (J - 1))
- Else
- Cells(I, J) = "" '以上條件不成立則為空字串
- End If
- If Cells(I, J) - Cells(I, (J - 2)) = 0 Then
- 'Call 等於0
- End If
- With Cells(I, J + 1) '求得兩者差異
- .Formula = "=IF(ISBLANK(" & .Offset(0, -1).Address & "),""""," & .Offset(0, -1).Address & " - " & .Offset(0, -2).Address & ")"
- With Cells(I, J + 2) '求得量測值
- '.Formula = "=IF(ISBLANK(" & .Offset(0, -2).Address & "),""""," & "c" & I & "+(Round(" & .Offset(0, -2).Address & [color=Red]" / " & .Offset(0, ".End(xlleft)+2).Address,0) ")[/color]
- End With
- End With
- If Cells(I, J) = "" Then '當此為空字
- Cells(I, J + 1) = "" '則顯示空字串
- Cells(I, J + 2) = ""
- End If
- Next I
- Set current = Nothing '釋放物件變數
- Next current
- MsgBox "Worksheets working Success!!" '訊息提示
- End Sub
複製代碼 |
|