Trying to paste only rows with data in certain columns

Xero

New Member
Joined
Jul 27, 2020
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi, everyone!
I am copying from one worksheet to another. My current code works perfectly, except it also copies the blank rows after my data. What I need it to do is only copy rows with data in column E. I also listed the range as A13 to L100, but L could be any number of rows. Can anyone help out?
Sub Rectangle1_Click()
Dim SourceRange As Range
Set SourceRange = ThisWorkbook.Worksheets("Input").Range("A13:L100")
Dim NextFreeCell As Range
Set NextFreeCell = ThisWorkbook.Worksheets("Work Transfer Log").Cells(Rows.Count, "B").End(xlUp).Offset(RowOffset:=1)
SourceRange.Copy
NextFreeCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("E14:I100").Select
Selection.ClearContents
Range("F3:F9").Select
Selection.ClearContents



End Sub
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,388
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Does this do what you want?
VBA Code:
Sub Rectangle1_Click()
Dim Lrw As Long
Dim SourceRange As Range
Lrw = ThisWorkbook.Worksheets("Input").Cells(Rows.Count, "E").End(xlUp).Row
Set SourceRange = ThisWorkbook.Worksheets("Input").Range("A13:L" & Lrw)
Dim NextFreeCell As Range
Set NextFreeCell = ThisWorkbook.Worksheets("Work Transfer Log").Cells(Rows.Count, "B").End(xlUp).Offset(RowOffset:=1)
SourceRange.Copy
NextFreeCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("E14:I100").Select
Selection.ClearContents
Range("F3:F9").Select
Selection.ClearContents



End Sub
 

Xero

New Member
Joined
Jul 27, 2020
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
This is exactly what I needed. Thanks!!!!!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,569
Messages
5,596,913
Members
414,110
Latest member
docops

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