Form VBA and deleting cells while form is open

mikechambers

Active Member
Joined
Apr 27, 2006
Messages
397
I'm trying to run code on a sheet while my form is still open. I have simplified this code a lot to isolate the issue in the simplest form. I have my main macro launching the form, and vbModeless seems to do nothing for me. Then when the DropDown list is changed, it runs another macro while the form is still open, which it needs to be open. The problem is, when it is changed, it runs the code Change macro, which then runs Macro1. This is where I have the problem. It fails when I try to delete some cells on a sheet. At this point where it fails, it will let me enter text into a cell thru VBA, but it will not let me delete cells. And the sheet is not protected.

I get the following error:

Runtime error 1004

Delete method of Range class failed

Any ideas? Seems like a simple mistake I'm making...


***in main module***
Sub LaunchForm()
UserForm1.Show vbModeless
End Sub


***in form code***
Private Sub UserForm_Initialize()
DropDown1.RowSource = "Sheet1!C1:C10"
End Sub

Private Sub DropDown1_Change()
Application.EnableEvents = False
List2Filter = DropDown1.Value
Run "Macro1"
End Sub

***in main module***
Private Sub Macro1()
Application.ScreenUpdating = False
Sheet1.Range("W42") = "hello" 'THIS WORKS
Sheet1.Range("W42").Delete shift:=xlUp 'THIS FAILS
End Sub
 

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.

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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