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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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
 
Upvote 0

Forum statistics

Threads
1,214,414
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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