Copy to next blank row

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
186
Office Version
  1. 2013
Hi,

I am performing a filter and copy/paste to next available row in another sheet, can anyone spot my error in my last part of my code please?

Thanks

Sheet3.Select

Dim sInput As String

sInput = Sheet1.Range("C2").Value
Sheet3.Range("A:A").AutoFilter Field:=1, Criteria1:="=*" & sInput & "*"

Range("A:A").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheet2.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
In this part, you are copying the entire column. Not only are the cells visible in the filter, you are also copying the blank cells that are below the filter. Then it is possible that the number of cells does not fit in the destination column.
Code:
[COLOR=#ff0000]Range("A:A").Select[/COLOR]
[COLOR=#ff0000]Selection.SpecialCells(xlCellTypeVisible).Select[/COLOR]
[COLOR=#ff0000]Selection.Copy[/COLOR]

Try this

Code:
Sub test()
  Dim sInput As String
  sInput = Sheet1.Range("C2").Value
  sheet3.Range("A:A").AutoFilter Field:=1, Criteria1:="=*" & sInput & "*"
  sheet3.AutoFilter.Range.Copy
  Sheet2.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,228
Members
453,025
Latest member
Hannah_Pham93

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