• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Add to Next Empty Row

Tech56

Member
Hi,

I made some transactions for August in rows 29 to 46 (Transactions sheet). I clicked the 'Add This Month's Recurring Transactions' to add September's recurring. It pasted to the bottom instead of starting in row 47. Can the code be modified to find the next blank row instead?

Thank You

Code:
Sub MoveTransX()
    Dim i As Long, lr As Long, lr2 As Long
    Dim s1 As Worksheet, s2 As Worksheet
Set s1 = Sheets("Recurring Log")
Set s2 = Sheets("Transactions")
Call Unprotect_Transactions


'check if already done for this month
If Month(Date) = Month(Range("J3")) Then
    MsgBox "You have already added these recurring transactions for this month."
    Call Protect_Transactions
    Exit Sub
Else
    lr = s1.Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 4 To lr
        If s1.Range("B" & i) <> "" Then
            s1.Range("A" & i & ":I" & i).Copy
            lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row + 1
            s2.Range("A" & lr2).PasteSpecial xlPasteValues
        End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    'store when last run
    s2.Range("J3") = Date
    MsgBox "This month's recurring transactions have been added."
    Call Protect_Transactions
End If
End Sub
 

Attachments

  • Money Manager 20.1.xlsm
    290.2 KB · Views: 9
Last edited:
Hi !​
Try If s1.Range("B" & i).Value > "" Then Sheet5.[A18].End(xlDown)(2).Resize(, 9).Value = Sheet9.Rows(i).Columns("A:I").Value …​
 
Is this what you meant?

Code:
Sub MoveTransX()
    Dim i As Long, lr As Long, lr2 As Long
    Dim s1 As Worksheet, s2 As Worksheet
Set s1 = Sheets("Recurring Log")
Set s2 = Sheets("Transactions")
Call Unprotect_Transactions


'check if already done for this month
If Month(Date) = Month(Range("J3")) Then
    MsgBox "You have already added these recurring transactions for this month."
    Call Protect_Transactions
    Exit Sub
Else
    lr = s1.Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 4 To lr
        If s1.Range("B" & i).Value > "" Then Sheet5.[A18].End(xlDown)(2).Resize(, 9).Value = Sheet9.Rows(i).Columns("A:I").Value 
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    'store when last run
    s2.Range("J3") = Date
    MsgBox "This month's recurring transactions have been added."
    Call Protect_Transactions
End If
End Sub
 
Last edited:
Back
Top