標題:
[發問]
型態不符和
[打印本頁]
作者:
alex520188
時間:
2014-11-19 10:51
標題:
型態不符和
各位前輩好
請問這段語法 紅字部份哪邊撰寫錯誤 他一直出現型態不符和
紅字部份 我要寫入的條件式是B2這個儲存格的位置
還請各位前輩多多指點
Sub 鋼筋計():D
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
複製代碼
作者:
luhpro
時間:
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
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)