Macro is not removing cells correctly from a form control button

shyy

Well-known Member
Joined
Nov 6, 2008
Messages
1,484
Hey everyone,

I have this macro where if I run it, it will work. However when I run it from my form, it doesn't work. What I want to do is select the active row and delete cells that don't have a formula.

When I run the macro within my form, it deletes all the cells, but when I run the macro without opening the form, it seems to always work. Anyone know why? Thanks in advance

Code:
    Range("D" & ActiveCell.Row & ":Z" & ActiveCell.Row).Select
    Selection.SpecialCells(xlCellTypeConstants).Select
    Selection.ClearContents
 
All controls on a form are ActiveX.

As I said, I have tried it with ActiveX controls both on a sheet and a form, and it works fine. If it still doesn't for you, put a stripped-down example on box.net and post a link.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Instead of Rows(ActiveCell.Row) try using ActiveCell.EntireRow.

I note that all the code posted used unqualified references. (Also, does your form activate a different sheet when you open it.)
 
Upvote 0
I'm unable to download your file from box. is it password-protected?
 
Upvote 0
There shouldn't be any password protection, try changing the extension to .XLSM. Its a 2007 format, but I changed it to .XLS since that still works.

I will try the ActiveCell.EntireRow thanks
 
Upvote 0
I tried this and it still would delete everything in the row. This form picks up the firs tab, which later will be given a name (something "underlying"

What do you mean by unqualified references?

Code:
Sub removecells()
   ' Range("D" & ActiveCell.Row & ":Z" & ActiveCell.Row).Select
   ' Selection.SpecialCells(xlCellTypeConstants).Select
   ' Selection.ClearContents
On Error Resume Next
ActiveCell.EntireRow.Range("D1:Z1").SpecialCells(xlCellTypeConstants).ClearContents
End Sub

Instead of Rows(ActiveCell.Row) try using ActiveCell.EntireRow.

I note that all the code posted used unqualified references. (Also, does your form activate a different sheet when you open it.)
 
Upvote 0
There shouldn't be any password protection, try try changing the extension ...
I can't download your file at all.
 
Upvote 0
The button works fine for me. You are aware that it clears the constants in the row of the active cell?
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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