Code Interpretation

  • Thread starter Thread starter JMay
  • Start date Start date
J

JMay

Using
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub

What kind of things (list most obvious) can happen to make this statement
TRUE?
TIA,
 
This will happen when more than one cell is selected and the user edits the
highlighted cell. Can't think of any other circumstances.

TH
 
here are a couple of ways:

Select A1:A10 and type BBB. But hit ctrl-enter instead of enter. You've filled
that range.

Copy A1:A10 to B1:B10 and you've got more than one cell.
 
Only selecting more than one cell and then changing the active cell to
trigger the event.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
selecting multiple cells and hitting delete to clear them would be very
common.
 
Thanks TH, but
I enter data in all cells A1:B4.
With A1 the activecell I highlight A1:B4
If I press F2 (on the automatically highlite Activecell - A1) and change the
data in it only
and press the enter key my MsgBox **does not** appear.
Using:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then
MsgBox ("Statement is True")
End If
End Sub

What am I missing?
 
Bob:

If I select more than one cell in my spreadsheet,
Let's say my cursor is in cell B1 and I drag over cells
to D5 (B1:D5 now selected) I'm unable to change the active cell, Right?
Are you talking about changing the active cell via code?
TIA,
JMay
 
OK, Yes, got-em!!

Dave Peterson said:
here are a couple of ways:

Select A1:A10 and type BBB. But hit ctrl-enter instead of enter. You've filled
that range.

Copy A1:A10 to B1:B10 and you've got more than one cell.
 
Thks Tom, yeah I'd forgotten that (tidbit)!
So now that I go back and "tab" I see my activecell change
But no MsgBox

Using:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then
MsgBox ("Statement is True")
End If
End Sub

What now?
 
I didn't suggest this action would fire an event. I just answered how to
change the activecell in a multi-cell selection.

for me, it fires neither change or selectionchange. Entering a value in the
active cell only produced a one cell target even with multiple cells
selected. Using Daves suggestion (multicell entry), it did fire a multicell
target (as expected). Deleting multiple cells did produce a multicell
target (as expected).
 
Tom:
Thanks for saying "Entering a value in the active cell only produced a one
cell target even with multiple cells selected." That is very meaningful.
Dave and your explanation have assisted me greatly...
JMay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top