How to copy and pastespecial only visible cells with VBA?

perola.rike

Board Regular
Joined
Nov 10, 2011
Messages
151
I'm simply trying to copy a named area from one sheet to another. But, Sheets("profil_diy").Range("diy_profil_area") is an area with some hidden rows. I want the code below to copy only the visible cells, which it doesn't...It copy also the hidden rows.
Sheets("profil_manuell").Range("profil_manuell_area") is a named cell, B2 on the "profil_manuell" sheet.

How to modify code to onlye copy visible cells?

I've searched a lot of forums, modifying the code, but with no luck.


Code:
Sheets("profil_diy").Range("diy_profil_area").Copy
With Sheets("profil_manuell").Range("profil_manuell_area")
.PasteSpecial (xlPasteAllUsingSourceTheme)
.PasteSpecial (xlPasteValuesAndNumberFormats)
.PasteSpecial (xlPasteColumnWidths)
End With
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Replace this line

Code:
Sheets("profil_diy").Range("diy_profil_area").Copy

With

Code:
Sheets("profil_diy").Range("diy_profil_area")[B][COLOR=#ff0000].SpecialCells(xlCellTypeVisible)[/COLOR][/B].Copy
 
Upvote 0
Thank you for answering. I've inserted your code-line. I believe I've tried that "specialcells" code before with no luck.
The following error occured: The textstrings included in the cells in the named range that are copied are not pasted in the new sheet. The values are not pasted. All formatting except for these texts/values is copied. Why?
 
Upvote 0
I found another way around the problem. In a separate column I used Filter to hide unused rows, not "hide rows" vba procedure. It seems like my original code copy only the visible cells when using filter, which is what I needed. With the other method, "hide unused", the hidden rows were still being copied with my old code. So, using filter solved my problem.
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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