PasteSpecial error - VBA

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good day,

I have the following code below and while it works, I've noticed it copies over the conditional formatting the previous range had which then deletes conditional formatting another range has, so I need to figure out how to stop that and I figured PasteSpecial xlPasteValues was the way to do it but I'm not sure how to implement that into this type of code.

VBA Code:
         If Not IsEmpty(Sheet1.Range("$B$5, $G$5, $J$5, $M$5")) Then
   
                With Sheet1
                    .Range("G2:H2").Copy .Range("K2")
                    .Range("G5:I32").Copy .Range("K5").PasteSpecial
                    .Range("C116:L140").Copy .Range("C142")
                End With
            End If

I get an error with this approach. I also tried Range.("").Value and Range("").PasteSpecial Paste:=xlPasteValues
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
To use paste special it needs to be on a separate line
VBA Code:
.Range("G5:I32").Copy
.Range("K5").PasteSpecial xlpastevalues
 
Upvote 0
Solution

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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