jolivanes made some mistakes in his code. We check whether the cells are merged with the MergeCells property. When we run the loop through all cells of the range, the line
will work correctly only for the first cell of the merged range, for the rest it will report an error. And there is no need to test whether the cells are merged. You can use MergeArea for any cell. More correct code (with merged cells check)
or without checking
In contrast, the code suggested by Marc L could look like this:
Sometimes I see codes where users clean cells with an empty string (""). In my opinion, this is not the correct solution. The Clear, ClearContents methods should be used, but these should be used in conjunction with MergeArea. And if we don't want to use these methods, cells can be cleared by assigning them Null. There are subtle differences between the "", vbNullString, Empty, Null assignments, but these are "invisible" to the average user. Personally, I recommend the use of Null. For example
or shorter the same
Artik
Bookmarks