So I'm having an issue in referring to a worksheet. I intend to open an input box whenever I find an empty cell on column B throughout the workbook, so I can input and change the empty cell value.
I am, however, getting an error (First was saying subscription out of range and I changed it, so now it says application/ object defined error) on this line:For i = 0 To Sheets(j).Cells(Rows.Count, i).End(xlUp).Row
Code:
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
Regards
For i = 0 To Sheets(j).Cells(Rows.Count, <HERE>intColNumber<HERE>).End(xlUp).Row
– Nathan_SavSheets(j).Cells(Rows.Count, i +1).End(xlUp).Row
– JerryT