VBA Excel:Cells.Value 上的错误 400
VBA Excel: Error 400 on Cells.Value
我在以下函数的 Cells.Value 上收到 400 错误:
Function Add_Buttons(myColumn)
Dim btn As Button
ActiveSheet.Buttons.Delete
Dim t As Range
'Search for last row
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
'Force-Update
Application.Calculate
'Generate a button for each cell, if it's not empty
For i = 3 To lastRow
Set t = Range(Cells(i, myColumn), Cells(i, myColumn))
If Cells(i, t.column - 1).Text = "Nicht OK" Then
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.RowHeight)
With btn
.OnAction = "'DieseArbeitsmappe.Update_DB """ & ActiveSheet.Cells(i, myColumn).Value & """'" 'THIS IS WHERE THE ERROR OCCURS
.Caption = "Update"
.Name = "Btn_" & ActiveSheet.Name & "_" & i
End With
End If
Next i
End Function
我在我的代码中找不到任何错误。这绝对是 ActiveSheet.Cells(i, myColumn).Value
的东西,因为没有这个参数,.OnAction
工作正常。
我成功了。如果您有类似的情况,请确保您在单元格中的引号已经转义。这样你就可以避免这个错误。
我在以下函数的 Cells.Value 上收到 400 错误:
Function Add_Buttons(myColumn)
Dim btn As Button
ActiveSheet.Buttons.Delete
Dim t As Range
'Search for last row
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
'Force-Update
Application.Calculate
'Generate a button for each cell, if it's not empty
For i = 3 To lastRow
Set t = Range(Cells(i, myColumn), Cells(i, myColumn))
If Cells(i, t.column - 1).Text = "Nicht OK" Then
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.RowHeight)
With btn
.OnAction = "'DieseArbeitsmappe.Update_DB """ & ActiveSheet.Cells(i, myColumn).Value & """'" 'THIS IS WHERE THE ERROR OCCURS
.Caption = "Update"
.Name = "Btn_" & ActiveSheet.Name & "_" & i
End With
End If
Next i
End Function
我在我的代码中找不到任何错误。这绝对是 ActiveSheet.Cells(i, myColumn).Value
的东西,因为没有这个参数,.OnAction
工作正常。
我成功了。如果您有类似的情况,请确保您在单元格中的引号已经转义。这样你就可以避免这个错误。