CodexBloom - Programming Q&A Platform

Excel VBA to Copy Conditional Formatting Between Sheets - Getting 'Method 'Range' of object '_Worksheet' scenarios' scenarios

πŸ‘€ Views: 14 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-16
excel vba conditional-formatting VBA

I'm trying to configure I'm trying to copy conditional formatting from one sheet to another in Excel using VBA, but I'm working with a 'Method 'Range' of object '_Worksheet' Failed' behavior... I have two sheets, 'Source' and 'Destination', and I want to transfer all the conditional formatting rules applied to a specific range on the 'Source' sheet to the same range on the 'Destination' sheet. Here’s the attempt I’ve made: ```vba Sub CopyConditionalFormatting() Dim sourceSheet As Worksheet Dim destSheet As Worksheet Dim sourceRange As Range Dim destRange As Range Set sourceSheet = ThisWorkbook.Sheets("Source") Set destSheet = ThisWorkbook.Sheets("Destination") Set sourceRange = sourceSheet.Range("A1:A10") Set destRange = destSheet.Range("A1:A10") sourceRange.Copy destRange.PasteSpecial Paste:=xlPasteFormats Application.CutCopyMode = False End Sub ``` When I run this code, I get the behavior mentioned above, and it seems to occur at the `destRange.PasteSpecial` line. I made sure that both sheets are indeed present and that the ranges are correctly defined. I've also checked for any merged cells, but there are none in the specified ranges. I've tried using `destSheet.Cells` instead of `destRange` but still faced the same scenario. Could there be any additional conditions I need to consider when copying formats, such as worksheet protection or hidden sheets? I’m currently using Excel 2019. Any insights would be greatly appreciated! I'm on Windows 10 using the latest version of Vba. I'm open to any suggestions. I recently upgraded to Vba latest. I appreciate any insights!