rowyn: (Me 2012)
[personal profile] rowyn

My Google-Fu has failed me. Help me, Social Media, you're my only hope.

I'm working on a ridiculously overcomplicated Excel workbook, with a bajillion triggered events based on the cell contents.

I want the user to be able to hit "delete" on one cell, and have the spreadsheet trigger an event that clears a varied assortment of other cells.

This workbook has existing code that already does this "clear assorted cells" operation whenever the cell is changed to one of the six values on its picklist. The picklist values are assigned from a sequence of cells elsewhere in the workbook. One of those six picklist cells is empty. If you choose the empty value from the picklist, it will trigger the "cell is empty" event. It does this with code that reads either:
* ElseIf IsEmpty(Target) 
* ElseIf Target.Text = ""

But if you hit the delete key, it doesn't trigger the "cell is empty" event. It looks like Excel doesn't consider the deleted cell to be a "Target" the way it does when the user selects an item from the picklist, because deleting the cell won't trigger an event phrased as EITHER "ElseIf IsEmpty(Target)" OR ElseIf IsEmpty(Target) = False, and one of those should be hit if it were triggering the "change happened" code at all. There's code that prevents the user from entering an option that's not on the picklist, but this won't stop the user from using the delete key.

So. Any idea how I get "delete cell contents" to trigger an event?

Date: 2015-07-30 06:47 pm (UTC)
vik_thor: (barcode)
From: [personal profile] vik_thor
(low level Excel user here…)
Are there conditional items in the cell that are getting deleted?
Or is the cell this is getting entered in a blank one, other than whatever is entered?

After deleting the contents of the cell, does changing the active cell trigger the actions you're looking for?

Date: 2015-07-30 07:54 pm (UTC)
From: [identity profile] terrycloth.livejournal.com
Private Sub Worksheet_Change(ByVal Target As Range) triggers on delete when I try it. You'd have to check that Target.Address was equal to the location of the picklist.

Date: 2015-07-31 02:19 am (UTC)
From: [identity profile] terrycloth.livejournal.com
That's the version I was using, and almost the exact same methodology (I skipped the Target.Address check and had it put up a message box unconditionally, but that seems like a weird part of it to fail).

Date: 2015-07-31 02:31 am (UTC)
From: [identity profile] terrycloth.livejournal.com
Target.Address = "$I$451"

But if I used =I451 it didn't work even for entering text, so presumably you were just paraphrasing. Huh.
Edited Date: 2015-07-31 02:32 am (UTC)

Date: 2015-08-01 12:36 am (UTC)
From: [identity profile] terrycloth.livejournal.com
Of course. Text is only entered in the first cell of a merged cell, but the selection that a command like 'clear cells' operates over is expanded to include the entire merged cell.

December 2025

S M T W T F S
 123456
78910111213
141516 17181920
21222324252627
28293031   

Most Popular Tags

Active Entries

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 3rd, 2026 05:49 am
Powered by Dreamwidth Studios