help adjusted code delete empty row when transfer invoice from sheet to another

abdelfattah

Board Regular
Joined
May 3, 2019
Messages
87
hello,
my code works but i need adjusted code when i press my macro ignore the empty rows from a19:e31 when delete these rows i suggest to be condition if a19 to a31 =0 then delete theses rows




HTML:
Sub TransferData()
    Dim Target As Range    
    Dim LastRow As Long    
    Dim R As Long

    LastRow = sheet1.Cells(sheet1.Rows.Count, "A").End(xlUp).Row 
    Set Target = sheet2.Cells(sheet2.Rows.Count, "A").End(xlUp)  

    For R = 2 To LastRow       
        sheet1.Range(sheet1.Cells(R, 1), sheet1.Cells(R, 5)).Copy _              
            Destination:=Target.Offset(R - 2)        
        With Target.Offset(R - 2, 4)         
            If .HasFormula Then .Value = sheet1.Cells(R, 5).Value       
        End With    
    Next R
    
    On Error Resume Next                ' error if the is a REF error in the sum range    
    Target.Offset(R - 3, 5).Value = WorksheetFunction.Sum(sheet2.Range("E33:E35"))

End Sub
 
Last edited by a moderator:

Forum statistics

Threads
1,077,662
Messages
5,335,564
Members
399,025
Latest member
alce

Some videos you may like

This Week's Hot Topics

Top