Copy to next blank row

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
184
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,213,536
Messages
6,114,205
Members
448,554
Latest member
Gleisner2

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