Copying Visable cells only

Perksy_no1

Well-known Member
Joined
Oct 27, 2011
Messages
598
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I've got a macro with copies certain data from 1 sheet to the next. The problem I have is that some times there is an autofillter on the data.

I think I need to add .SpecialCells(xlCellTypeVisible) in to the code some where but im not sure where.

my current code is as follows. This is only a part of the code. It also copies other columns across to the other sheet

Code:
Sub CopyPasteMacro()
'
    With Sheets("Imprint Data")
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        Set rngToCopy = .Range(.Range("B6:B" & LastRow), .Range("B6:B" & LastRow))
    End With
    rngToCopy.Copy
        Sheets("To Key @ TE Imprint").Range("D4").PasteSpecial Paste:=xlPasteValues
End Sub

Thanks for any help or advice in advance

Mark
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Thanks for any one who looked at this but I've cracked it now thanks

Code:
Sub CopyPasteMacro()
'
        With .Range("B6:B" & LastRow)
            .SpecialCells(xlCellTypeVisible).Copy Sheets("To Key @ TE Imprint").Range("D4")
        End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,207,422
Messages
6,078,438
Members
446,337
Latest member
nrijkers

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