skip copy empty rows from sheet to another

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi
i try ignoring empty rows when i copy the last ten rows from sheet1 to sheet2 but it doesn't success
any idea to do that

VBA Code:
Sub CopyLines()

    Dim LastRow, LastRow1 As Long

LastRow = Sheets("Sheet1").Cells(Rows.Count, "b").End(xlUp).Row

            Sheets("Sheet1").SpecialCells(xlCellTypeBlanks).Delete xlUp

     Sheets("Sheet1").Range("A" & LastRow - 9 & ":B" & LastRow).Copy Sheets("Sheet2").Range("h11")

End Sub
thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
VBA Code:
Sub CopyLines()
Dim LastRow As Long
With Sheets("Sheet1")
   .Range("B:B").SpecialCells(xlBlanks).EntireRow.Delete
   LastRow = .Cells(Rows.Count, "b").End(xlUp).Row
   .Range("A" & LastRow - 9 & ":B" & LastRow).Copy Sheets("Sheet2").Range("h11")
End With
End Sub
 
Upvote 0
Solution
thanks fluff what if stay blank row in sheet1 and ignore it in sheet2 after copy
 
Upvote 0
If you want to copy the last 10 non blank cells, then you will need to loop up from the bottom of col B to find the right row & then copy
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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