What's wrong with this?

ryancgarrett

Board Regular
Joined
Jun 18, 2011
Messages
122
It's 2 in the morning and I'm falling asleep as I code my project lol. I can't figure out for the life of me what I have done wrong here. Can anyone help?

Code:
Sub tranAcct()
    Dim eRow As Integer
    Dim nextBox As Integer
    
    eRow = BlankRow("Journal", 3, 2) + 1
    
    With frmTransactionEntry
        For nextBox = 1 To 6
            If .Controls("cbxAccount" & nextBox).Value <> 0 Then
                Sheets("Journal").Cells(eRow, 2).Value = .Controls("cbxAccount" & nextBox).Value
                If .Controls("optCredit" & nextBox).Value = True Then
                    Sheets("Journal").Cells(eRow, 2).InsertIndent 1
                    Sheets("Journal").Cells(eRow, 7).Value = .Controls("tbxAmount" & nextBox)
                ElseIf .Controls("optDebit" & nextBox).Value = True Then
                    Sheets("Journal").Cells(eRow, 5).Value = .Controls("tbxAmount" & nextBox)
                End If
                eRow = eRow + 1
            End If
        Next
    End With
    
    Sheets("Journal").Cells(eRow, 2).Value = frmTransactionEntry.tbxDescription
    Sheets("Journal").Cells(eRow, 2).InsertIndent 2
    Sheets("Journal").Cells(eRow, 2).Font.Italic = True
    
End Sub

The form has 6 lines on it for transactions, but if there aren't 6 lines it shouldn't still include them when putting in the description. Not sure if that made sense, but basically there are two transactions on rows 4 and 5, and then 4 blank rows and then my description. How do I get it to overlook those blank lines on the form?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
It's 2 in the morning and I'm falling asleep as I code my project lol. I can't figure out for the life of me what I have done wrong here. Can anyone help?

Code:
Sub tranAcct()
    Dim eRow As Integer
    Dim nextBox As Integer
 
    eRow = BlankRow("Journal", 3, 2) + 1
 
    With frmTransactionEntry
        For nextBox = 1 To 6
            If .Controls("cbxAccount" & nextBox).Value <> 0 Then
                Sheets("Journal").Cells(eRow, 2).Value = .Controls("cbxAccount" & nextBox).Value
                If .Controls("optCredit" & nextBox).Value = True Then
                    Sheets("Journal").Cells(eRow, 2).InsertIndent 1
                    Sheets("Journal").Cells(eRow, 7).Value = .Controls("tbxAmount" & nextBox)
                ElseIf .Controls("optDebit" & nextBox).Value = True Then
                    Sheets("Journal").Cells(eRow, 5).Value = .Controls("tbxAmount" & nextBox)
                End If
                eRow = eRow + 1
            End If
        Next
    End With
 
    Sheets("Journal").Cells(eRow, 2).Value = frmTransactionEntry.tbxDescription
    Sheets("Journal").Cells(eRow, 2).InsertIndent 2
    Sheets("Journal").Cells(eRow, 2).Font.Italic = True
 
End Sub

The form has 6 lines on it for transactions, but if there aren't 6 lines it shouldn't still include them when putting in the description. Not sure if that made sense, but basically there are two transactions on rows 4 and 5, and then 4 blank rows and then my description. How do I get it to overlook those blank lines on the form?


I would put an else in between the two ifs
If .Controls("cbxAccount" & nextBox).Value <> 0 Then
Sheets("Journal").Cells(eRow, 2).Value = .Controls("cbxAccount" & nextBox).Value

Else
'not included or nothing or whatever
If .Controls("optCredit" & nextBox).Value = True Then
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top