skip copy empty rows from sheet to another

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
995
Office Version
  1. 2010
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,927
Office Version
  1. 365
Platform
  1. Windows
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
 

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
995
Office Version
  1. 2010
thanks fluff what if stay blank row in sheet1 and ignore it in sheet2 after copy
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,927
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,927
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,258
Messages
5,641,162
Members
417,195
Latest member
Vishal kumar

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
Top