"Reset Form" Command Button Will not clear merged cells.

Wulf

Active Member
Joined
Dec 1, 2004
Messages
395
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that we use quite often, and am trying to make it a little more "user-friendly". So, to facilitate rapid-resuage, I inserted a Command Button (ActiveX Control), named it "Reset Form, and have this as the code:

Private Sub CommandButton1_Click()
Range("C3").ClearContents
Range("C4").ClearContents
Range("C5").ClearContents
Range("F3").ClearContents
Range("F5").ClearContents
Range("D8").ClearContents
Range("D9").ClearContents
Range("D14").ClearContents
Range("D16").ClearContents
Range("D29").ClearContents
Range("D31").ClearContents
Range("G31").ClearContents
Range("F4") = "=VLOOKUP(F3,Sheet2!A15:C17,3,0)"
Range("D11") = "X:\Development\Database Requests to be Completed\Database Downloads"
End Sub

HOWEVER, "D" cells 14, 16, 29, and 31 are merged with the neighboring "E" cell.

When I run it, I get "Run-Time '1004': We can't do that to a merged cell".

I did several searched through the forums, and found some similar topics, and tried some of the suggested fixes, but couldn't get any to work for me.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It's best to avoid merged cells, as they cause far to many problems.
Try using centre across selection instead.
 
Upvote 0
Try:
Code:
Private Sub CommandButton1_Click()
    Range("C3").ClearContents
    Range("C4").ClearContents
    Range("C5").ClearContents
    Range("F3").ClearContents
    Range("F5").ClearContents
    Range("D8").ClearContents
    Range("D9").ClearContents
    Range("D14").MergeArea.ClearContents
    Range("D16").MergeArea.ClearContents
    Range("D29").MergeArea.ClearContents
    Range("D31").MergeArea.ClearContents
    Range("G31").ClearContents
    Range("F4") = "=VLOOKUP(F3,Sheet2!A15:C17,3,0)"
    Range("D11") = "X:\Development\Database Requests to be Completed\Database Downloads"
End Sub

You should avoid using merged cells because they almost always create havoc for Excel macros. Do a little research into "Merge Across Selection". It most often has the same effect as merging cells without the problems.
 
Upvote 0
Many thanks! the addition of the ".MergeArea" did it.

Much appreciated.
 
Upvote 0
Glad we could help and thank you for the "Rep". :)
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,837
Members
449,193
Latest member
MikeVol

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