From: tbone on
In the Worksheet_SelectionChange event, is there a way to determine
the range of cells currently highlighted with the marquee, given that
CutCopyMode is true?

The reason I'd like to know is that I am changing the Enable state of
a command button depending on the Target range (i.e. where the user is
placing the cursor); if in a certain range, the button is to be
enabled, otherwise it is to be disabled. The problem is that setting
the Enable property on the button clears the CutCopyMode state. This
breaks copy-paste functionality.

Since I already have a selection change event handler (for other
reasons), I intended to work around this issue by noting the source
range, changing the button state as required, reselecting the source
range, and then reactivating the Target. So instead of just:

btnAddRow.Enabled = enb ' set button state as req'd

I planned to instead do:

If btnAddRow.Enabled <> enb Then ' if change req'd
If Application.CutCopyMode <> 0 Then ' if marquee is up
Set r = Application.CutCopySourceRange ' get marquee range
btnAddRow.Enabled = enb ' set enable state
r.SetAsCopySource ' restore marquee
Target.Activate ' restore ActiveCell
btnAddRow.Enabled = enb ' just set enable property as required
End If
End If

I would entertain alternatives. I thought about tracking the current
selection, but I'm not sure I can reliably determine the actual range
with the marquee that way.

Pages: 1
Prev: Constants
Next: sql to database