Cannot change part of merged cell

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
574
Office Version
  1. 365
Platform
  1. Windows
I have several merged cells and I have the code listed below to clear all of these out. When it gets to the line highlighted in red, it crashes with the message "Cannot change part of a merged cell". The problem is that I am not trying to change part of the merged cell, I am trying to clear all of it out. Don't know what the issue is.

Thanks for the help.

Robert

Rich (BB code):
'clear out the additional lots covered section.
Range("AY11:AY25").ClearContents
Range("R9:U9").ClearContents
Range("W9:AA9").ClearContents

If Range("AZ11").Value <> "" Then
    Range("R11:U11").ClearContents
    Range("W11:AA11").ClearContents
ElseIf Range("AZ13").Value <> "" Then
    Range("R13:U13").ClearContents
    Range("W13:AA13").ClearContents
ElseIf Range("AZ15").Value <> "" Then
    Range("R15:U15").ClearContents
    Range("W15:AA15").ClearContents
ElseIf Range("AZ17").Value <> "" Then
    Range("R17:U17").ClearContents
    Range("W17:AA17").ClearContents
ElseIf Range("AZ19").Value <> "" Then
    Range("R19:U19").ClearContents
    Range("W19:AA19").ClearContents
ElseIf Range("AZ21").Value <> "" Then
    Range("R21:U21").ClearContents
    Range("W21:AA21").ClearContents
ElseIf Range("AZ23").Value <> "" Then
    Range("R23:U23").ClearContents
    Range("W23:AA23").ClearContents
ElseIf Range("AZ25").Value <> "" Then
    Range("R25:U25").ClearContents
    Range("W25:AA25").ClearContents
End If
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Merged cells and VBA don't get on. You need to refer to the top left cell of the merged range. Maybe

Code:
Range("W9").ClearContents
 
Upvote 0
Crazy, but now it highlights that line, with the same error message. Stupid VBA! What can I try next?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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