Copy data from a filtered list to another filtered list

martinequilibrium

New Member
Joined
Feb 26, 2016
Messages
13
Dear Users,

I'm trying to copy a range of filtered cells to a destination range of other similar filtered cells.
Here is a little example I'm trying to use with some VBA code I found below.


QFcPkGGQRbc3QcbeHeDROluJ7-71Wq8PFd8L-AZJ6jnZ5OYxdBNo9X0mFAWQoefavlGezgfvj12Fb8PQrbrvxPaiXMvdbfZx6CKIVoCcXpGBD0KwDxWWX9ghRESVnW687372Y-DqFO4oN9ST1t8bsMLnwfhm7Oj_DfHKx26vBvbyd6FNBG4gTT3oTWUukcg9iwZ5rUimOvWvtvMIuRXckEnsTzaLVtkGrwc713TqzoFSzYiY39c24Ez0Pp8qJoaw7--hjikvvIP2xvSkaHBdGBLARPN7bNp2CjM4vUKQdxIDFLLabNCOt83ePS9EiVjGUAE-bbNix9HP1ueAiiK6HP1hi0RNi72WYr2jXfssPwxF3Y1I-XjqvXJahyES-2uPKwh_gdCwIG6Lp_I2PxKTtBHEVGEEtJB2banSNuhV2ove4PTl7tFDVjsVoHc4cbj5yO64DD4ShBO8NjFZE86eu7K24h79YtePFtuyvKrjNGJiPiPvhjfRZpKffaktK1eOJDwbZakezjCHZkrY2tQhnHWy5DYyigY_1UZNqNXOA6a5N1APUhzqM3G8UkZRARS7lU1G=w986-h411-no


Refering to http://answers.microsoft.com/en-us/...y/ebec7959-60bd-4903-ad8e-391f2f8d8479?page=3
Ibrahim Chakaleidos code.

Code:
Sub PasteToVisibleCellsOnly()
' 2016 Ibrahim Chakaleidos - *** Email address is removed for privacy ***
' Paste to visible cells only from clipboard or another sheet
' Compatible with Excel 2007, 2010


    Dim DataObj As MSForms.DataObject
    Dim strArray, strArray2
    Dim i As Long, j As Long
    Dim myString As String
    Dim Variable() As Variant


    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard
    myString = DataObj.GetText(1)
    strArray = Split(myString, vbNewLine)


' Paste party begins
    For i = LBound(strArray) To UBound(strArray)
        strArray2 = Split(strArray(i))


        For j = LBound(strArray2) To UBound(strArray2)
        ReDim Preserve Variable(j)
            Variable(j) = strArray2(j)


    Do Until ActiveCell.Offset(0, 0).EntireRow.Hidden = False
    ActiveCell.Offset(1, 0).Select
    Loop
ActiveCell.Value = Variable(j)
       ActiveCell.Offset(1, 0).Select
    Next j
    Next i


' This loop only to select the next visible cell after pasted data
      Do Until ActiveCell.Offset(0, 0).EntireRow.Hidden = False
    ActiveCell.Offset(1, 0).Select
    Loop


End Sub


I'm getting a:
Run-time error '-2147221404 (80040064)':
DataObject:GetText Estructura FORMATECT no válida

I do have the MsForms reference enabled.

Thanks!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this:
Code:
Sub CopyVisibleToVisible()
'Copy paste(value):
'from filtered to filtered range
'from filtered to unfiltered range
'from unfiltered to filtered range
'Not work on hidden column

    Dim rngA As Range
    Dim rngB As Range
    Dim r As Range
    Dim Title As String
    Dim ra As Long
    Dim rc As Long
    
    Title = "Copy Visible To Visible"
    Set rngA = Application.Selection
    Set rngA = Application.InputBox("Copy Range :", Title, rngA.Address, Type:=8)
    
    Set rngB = Application.InputBox("Paste Range (select the first cell only):", Title, Type:=8)
    Set rngB = rngB.Cells(1, 1)
    Application.ScreenUpdating = False

    ra = rngA.Rows.count
    rc = rngA.Columns.count
    Set rngA = rngA.Cells(1, 1).Resize(ra, 1)
    
    For Each r In rngA.SpecialCells(xlCellTypeVisible)
      rngB.Resize(1, rc).Value = r.Resize(1, rc).Value
        Do
          Set rngB = rngB.Offset(1, 0)
        Loop Until rngB.RowHeight <> 0
    Next
    
    Application.Goto rngB
    Application.ScreenUpdating = True
    Application.CutCopyMode = False

End Sub
 
Upvote 0
Sorry for the delay in the reply:
What an elegant and marvelous piece of code.
Thank you so much!
It does what asked and more and so simply coded. Thanks Akuini :laugh:
You guys rock!
 
Upvote 0
Sorry for the delay in the reply:
What an elegant and marvelous piece of code.
Thank you so much!
It does what asked and more and so simply coded. Thanks Akuini :laugh:
You guys rock!

You're welcome & thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,214
Members
453,024
Latest member
Wingit77

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