Lindsay0385
New Member
- Joined
- Dec 21, 2016
- Messages
- 30
Hi - Just a general question, as I'm confused about this. A while ago I created a macro with the macro recorder that uses relative references. I was able to clear the contents of merged cells while using that macro and didn't think anything of it, as it worked as expected.
Example (where A1:K1 is a merged cell, F3:K3 are merged, etc.)
But I tried to reuse the code in another project by copying and pasting the code and changing the values, every time I ran the macro, I got an error message saying that it wasn't possible do to that with a merged cell.
Eventually I remembered that I created the original macro via recording, and I did the same for my new project and it worked perfectly. The code looks exactly the same as what I typed, but it works without errors.
Why would this happen? So strange.
Thanks,
Lindsay
Example (where A1:K1 is a merged cell, F3:K3 are merged, etc.)
Code:
ActiveCell.Offset(1, 2).Range("A1:K1,F3:K3,H5:K5,F7:K8").ClearContents
But I tried to reuse the code in another project by copying and pasting the code and changing the values, every time I ran the macro, I got an error message saying that it wasn't possible do to that with a merged cell.
Eventually I remembered that I created the original macro via recording, and I did the same for my new project and it worked perfectly. The code looks exactly the same as what I typed, but it works without errors.
Why would this happen? So strange.
Thanks,
Lindsay