Paste All Cells as Values on a Hidden Sheet - VBA

eoinymc

Board Regular
Joined
Jan 29, 2009
Messages
203
Hi,

I want to copy and paste all cells as values on a hidden sheet.

When the sheet is not hidden, I currently do this:

Code:
Cells.Select                Selection.Copy
                Selection.PasteSpecial Paste:=xlPasteValues

However, I know you cannot use select on a hidden sheet.

Has anyone got any ideas how to do this?

Cheers,

E
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try like this

Code:
With Sheets("Sheet1").UsedRange
    .Value = .Value
End With
 
Upvote 0
You answered your own question really. Don't use Select. Something like:

<code>
sheets("myworksheet").Range("myrange").Copy
sheets("myworksheet2").Range("myrange2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
</code>

hope that helps

mrHopko
 
Upvote 0
Thanks Peter and mrHopko,

Peter, you're is quite simple and works great!

One other related question you may be able to help me with...

How do I paste special formulas without using select?

Code:
Range(Cells(4, 11), Cells(55, 11)).Copy
Range(Cells(4, 11), Cells(55, 23)).Select
Selection.PasteSpecial Paste:=xlPasteFormulas

Thanks,

E
 
Upvote 0
Try

Code:
Range(Cells(4, 11), Cells(55, 11)).Copy
Range(Cells(4, 11), Cells(55, 23)).PasteSpecial Paste:=xlPasteFormulas
 
Upvote 0
That's perfect Peter....Great...

One final one and my code will have been transformed to allow all sheets to be hidden!

This works when not hidden, can it be transformed to work with hidden?

Code:
Range(Cells(i, 11 + CumMonth - 1), Cells(i, 23)).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent3
            .TintAndShade = 0.599993896298105
            .PatternTintAndShade = 0
        End With

Thank you so much for all your help!

E
 
Upvote 0
That's perfect Peter....Great...

One final one and my code will have been transformed to allow all sheets to be hidden!

This works when not hidden, can it be transformed to work with hidden?

Code:
Range(Cells(i, 11 + CumMonth - 1), Cells(i, 23)).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent3
            .TintAndShade = 0.599993896298105
            .PatternTintAndShade = 0
        End With

Thank you so much for all your help!

E

Think about it... whatever you select becomes the selection, so just use what you selected in place of the selection directly...

Code:
With Range(Cells(i, 11 + CumMonth - 1), Cells(i, 23)).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.599993896298105
    .PatternTintAndShade = 0
End With
 
Last edited:
Upvote 0
Try

Code:
With Range(Cells(i, 11 + CumMonth - 1), Cells(i, 23)).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.599993896298105
    .PatternTintAndShade = 0
End With
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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