This document provides a solution for pasting data onto filtered rows in Excel without pasting onto hidden rows. It involves using VBA macros to paste data only onto visible rows. The user is instructed to copy a range of cells, select a copy range and paste range via input boxes, and run a VBA macro called "PasteOnVisibleCells" which will paste the copied cells only onto visible rows by checking the row height before pasting.
2. • When we paste data on filtered rows it always past it on both visible and
hidden rows. And if you are doing this for a huge set of data then I am sure
you must be pasting it manually and wasting lot of time and efforts. Don’t
worry guys, we have a solution for this but only through VBA.
• So let’s see an example, below is a screenshot of a filtered data:
Pasting Data on Filtered Rows
6/29/2017 www.nurturetechacademy.in 2
3. When you simply use Copy and paste it looks like this:
6/29/2017 www.nurturetechacademy.in 3
4. • So it will get pasted on hidden rows also, to avoid the same, please follow the below steps :
• Press Alt + F11 keys simultaneously, and a Microsoft Visual Basic for Applications (VBA)
window will open.
• Click Insert > Module, then paste below VBA code to the Module window.
• Sub PasteOnVisibleCells()
• Dim rg1 As Range
• Dim rg2 As Range
• Dim CopyRg As Range
• Dim PasteRg As Range
• Set CopyRg = Application.Selection
• Set CopyRg = Application.InputBox("Copy Range :", , CopyRg.Address, Type:=8)
• Set PasteRg = Application.InputBox("Paste Range:", , Type:=8)
• For Each rg1 In CopyRg
• rg1.Copy
• For Each rg2 In PasteRg
• If rg2.EntireRow.RowHeight > 0 Then
• rg2.PasteSpecial
• Set PasteRg = rg2.Offset(1).Resize(PasteRg.Rows.Count)
• Exit For
• End If
• Next
• Next
• Application.CutCopyMode = False
• End Sub
6/29/2017 www.nurturetechacademy.in 4
5. Click F5 key or the Run button, a dialog box will appear for you to
select Range to copy
6/29/2017 www.nurturetechacademy.in 5
6. After selecting the range, click OK, and then another dialog box will appear
for you to select a range to paste the copied data in.
Click OK to get your desired result.
6/29/2017 www.nurturetechacademy.in 6