ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy rows, but exclude blank rows (https://www.excelbanter.com/excel-programming/344322-copy-rows-but-exclude-blank-rows.html)

Mary[_9_]

Copy rows, but exclude blank rows
 
I have a worksheet with three columns that has over 1000 rows. What I want
to do is copy a specific range to another workbook, but to exclude any rows
that might be blank.

Thanks
Mary



Patrick Molloy[_2_]

Copy rows, but exclude blank rows
 
assuming no rows have blanks apart from those to delete then

Option Explicit
Sub test()
CopyRows Selection, Sheet2.Range("B2")
End Sub
Sub CopyRows(source As Range, target As Range)
With target.Resize(source.Rows.Count, source.Columns.Count)
.Value = source.Value
.SpecialCells(xlCellTypeBlanks).Delete
End With
End Sub

sheet2 is an empty sheet
select your range i=on sheet1 and run the code
you can easily adapt the test procedure for specific ranges

example
CopyRows Sheet1.Range("MyData"), Sheet2.Range("B2")


"Mary" wrote:

I have a worksheet with three columns that has over 1000 rows. What I want
to do is copy a specific range to another workbook, but to exclude any rows
that might be blank.

Thanks
Mary





All times are GMT +1. The time now is 10:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com