In sheet1 I have a list of data with 100 records A1:A100, In sheet2 I have a list of 10 records A1:A10. When I filter Sheet1 by color I get 10 records. I would like to paste the 10 records from sheet2 into the yelow filtered cells only. but when
I do it, it overides all other cells in between. I tried to select visible cells only before pasting but it didn't help.
I found an answer by Bob Umlas, Excel MVP http://social.answers.microsoft.com/Forums/en-US/excslcreate/thread/ebec7959-60bd-4903-ad8e-391f2f8d8479
Select the cells to copy, run this code:
Sub Copy_Filtered_Cells()
Set from = Selection
Set too = Application.InputBox("Select range to copy selected cells to", Type:=8)
For Each Cell In from
Cell.Copy
For Each thing In too
If thing.EntireRow.RowHeight > 0 Then
thing.PasteSpecial
Set too = thing.Offset(1).Resize(too.Rows.Count)
Exit For
End If
Next
Next
End Sub
it seems to be working, thanks
Thank you for taking the time to post this solution. This worked for me.
NOTE: Before following the steps below save a copy of your file in-case you need to revert back.
For less savvy users... to use the solution above follow these steps (Excel 2010):
- Enable Developer console in Excel by navigating to File > Options, then select the Customize Ribbon tab, on the right hand side check the box next to Developer.
- Click on the Developer tab on the top ribbon and then click Visual Basic.
- Once in Visual Basic double click the Sheet you're working with in Excel and paste the following code in the box that opens:
Sub Copy_Filtered_Cells()
Set from = Selection
Set too = Application.InputBox("Select range to copy selected cells to", Type:=8)
For Each Cell In from
Cell.Copy
For Each thing In too
If thing.EntireRow.RowHeight > 0 Then
thing.PasteSpecial
Set too = thing.Offset(1).Resize(too.Rows.Count)
Exit For
End If
Next
Next
End Sub
Note: This is now saved as a macro and future uses can be done by pressing Alt+F8 and using the Copy_Filtered_Cells macro.
- Close the Visual Basic window.
- Ensure the data you're copying is OUTSIDE of the filtered rows (e.g at the bottom of the spreadsheet).
- Select the data you're copying, then press Alt+F8 to bring up Macros, then run Copy_Filtered_Cells. Immediately following this an Input box will come up and ask you for your range you would like to copy the cells to (the cells should already be filtered)
select the cells or type in the range and hit OK.
Now when you un-filter your cells the data should only be copied into the cells that were previously filtered.