所以我在談論工作表時遇到了問題。我打算在整個工作簿中找到列B上的空單元格時打開輸入框,以便輸入和更改空單元格值。 我,然而,得到一個錯誤(第一個是說的訂閱超出了範圍,我改變了它,所以現在說應用/對象定義的錯誤),在這條線:
For i = 0 To Sheets(j).Cells(Rows.Count, i).End(xlUp).Row
參考工作表
代碼:
Dim Country As Variant
Dim Capital As Variant
Dim CapitalValue As Variant
Dim i As Integer
Dim j As Integer
' Select *first line of data*
Range("B1").Select
' Loop to stop when an empty cell is reached.
For j = 1 To Worksheets.Count
j = ActiveSheet.Index
Range("B1").Select
For i = 0 To Sheets(j).Cells(Rows.Count, i).End(xlUp).Row
'Select the Country Cell
ActiveCell.Offset(i, 0).Select
CapitalValue = ActiveCell.Value
'If Country is empty
If CapitalValue = "" Then
MsgBox ("No more Capitals")
Else
'Input Capital values
CapitalValue = ActiveCell.Value
Country = ActiveCell.Offset(0, -1).Value
Capital = InputBox("Capital of " & Country, "Capital Input")
CapitalValue = Capital
End If
Next i
Next j
問候
我認爲這是因爲你正在使用我兩次'對於i = 0到表(j ).Cells(Rows.Count, intColNumber ).End(xlUp).Row' –
Sheets().Cells()方法的參數必須大於0. 'Sheets(j).Cells(Rows.Count ,i +1).End(xlUp).Row' – JerryT