bostenson
02-23-2021, 04:57 PM
I want to find the next blank row in a newly added worksheet but I have a subscript out of range error in line WSNr = Worksheets(i).Cells(Rows.Count, "A").End(xlUp).Row + 1. This is the complete code:
Private Sub cmdSaveGL_Click()
Dim WSNr As Long
Dim a As Integer
Dim i As Long
a = ThisWorkbook.Worksheets.Count
' Find next blank row
WSNr = Worksheets(i).Cells(Rows.Count, "A").End(xlUp).Row + 1
' Add Expense data to Registers
If Me.cmbGLCategory.value = "Expense" Then
For i = 1 To a
If Worksheets(i).Name = cmbGLCashAcct.value Then
Worksheets(i).Range("A" & WSNr).value = Me.txbGLName.value
End If
Next
End If
End Sub
What am I missing in my code in order to find the blank row in the new sheet? Thanks in advance.
- Ben
Private Sub cmdSaveGL_Click()
Dim WSNr As Long
Dim a As Integer
Dim i As Long
a = ThisWorkbook.Worksheets.Count
' Find next blank row
WSNr = Worksheets(i).Cells(Rows.Count, "A").End(xlUp).Row + 1
' Add Expense data to Registers
If Me.cmbGLCategory.value = "Expense" Then
For i = 1 To a
If Worksheets(i).Name = cmbGLCashAcct.value Then
Worksheets(i).Range("A" & WSNr).value = Me.txbGLName.value
End If
Next
End If
End Sub
What am I missing in my code in order to find the blank row in the new sheet? Thanks in advance.
- Ben