Copy Paste to visible cells only with different sheets / workbooks

EhcacommenceVBAhum

New Member
Joined
Sep 3, 2017
Messages
1
Hi everyone !

Thanks to anyone affording time to read this and possibly help
001.gif


Here is my issue :
I'd like to copy data from a filtered column, then paste it to a filtered column in a different sheet, or even a different workbook.
I have a macro that works perfectly well to do that in single sheet. But excel crashes if I try to use it to paste in a different sheet or workbook.

Any idea of a way around ?


Scenario : Some cells in a column with header "Count 1" in Sheet 1 contain umerical values. This column filtered so that blank cells aren't visible.
I'd like to copy visible cells from "Count 1" of Sheet 1 and paste them in a column with header "Count 1" of another sheet where different rows are filtered.
Again, any solution working for different sheets would be awesome, but any solution solution working for different workbooks would be even better !
001.gif


Here the code I use that only works in a single sheet (and therefore for ranges with same hiden rows) :

Code:
Sub Copy_Paste_Visible_Cells_Only() 
    Dim rngtocopy As Range 
    Dim rngtopasteto As Range 
    Dim cell As Range 
    Dim ccount As Long 
    Dim i As Long 
    On Error Resume Next 
    Application.DisplayAlerts = False 
    Set rngtocopy = Application.InputBox("Select the filtered range to copy !", "Select Filtered Cells", Type:=8) 
    If rngtocopy Is Nothing Then Application.DisplayAlerts = True: Exit Sub 
    Set rngtopasteto = Application.InputBox("Select the destination cell to paste to !", "Select Paste Destination", Type:=8) 
    If rngtopasteto Is Nothing Then Application.DisplayAlers = True: Exit Sub 
    On Error GoTo 0 
    Application.DisplayAlerts = True 
    ccount = rngtocopy.Columns.Count 
    For Each cell In rngtocopy.Columns(1).SpecialCells(xlCellTypeVisible) 
        Do 
            i = i + 1 
        Loop Until Not rngtopasteto(1).Offset(i).EntireRow.Hidden 
        rngtopasteto(1).Offset(i).Resize(1, ccount).Value = cell.Resize(1, ccount).Value 
    Next 
End Sub


Thanks again for your time !
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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