Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Worksheet_Change() and range question

On my spreadsheet, I merged the cells N10, O10, and P10
into a single cell.

I then put the following code in my Worksheet_Change()
function:

Private Sub Worksheet_Change(ByVal Target As Range)

MsgBox CStr(Target.Address(0, 0))

End Sub


Now, if you enter data into cell N10 on the spreadsheet,
the message box will return with "N10". However, if you
DELETE the contents of cell N10, then the message box
will say "N10:P10". Why is this?? How can I tell
the "Target" variable to just give me "N10" string???
(I guess I'm too lazy to write code that parses range
strings, haha)

Thanks!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Worksheet_Change() and range question

Try this MsgBox statement instead...

MsgBox CStr(Target(1).Address(0, 0))

Note: The only change I made was to add (1) immediately after Target
keyword.

--
Rick (MVP - Excel)


"Robert Crandal" wrote in message
...
On my spreadsheet, I merged the cells N10, O10, and P10
into a single cell.

I then put the following code in my Worksheet_Change()
function:

Private Sub Worksheet_Change(ByVal Target As Range)

MsgBox CStr(Target.Address(0, 0))

End Sub


Now, if you enter data into cell N10 on the spreadsheet,
the message box will return with "N10". However, if you
DELETE the contents of cell N10, then the message box
will say "N10:P10". Why is this?? How can I tell
the "Target" variable to just give me "N10" string???
(I guess I'm too lazy to write code that parses range
strings, haha)

Thanks!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Worksheet_Change() and range question

Thanks....you're the best!


"Rick Rothstein" wrote in message
...
Try this MsgBox statement instead...

MsgBox CStr(Target(1).Address(0, 0))

Note: The only change I made was to add (1) immediately after Target
keyword.

--
Rick (MVP - Excel)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Worksheet_Change() and range question

Robert,

It's not that big a job to check if there's a colon

Private Sub Worksheet_Change(ByVal Target As Range)
If InStr(Target.Address(0, 0), ":") 0 Then
MsgBox Left(Target.Address(0, 0), InStr(Target.Address(0, 0), ":") - 1)
Else
MsgBox Target.Address(0, 0)
End If
End Sub

Mike

"Robert Crandal" wrote:

On my spreadsheet, I merged the cells N10, O10, and P10
into a single cell.

I then put the following code in my Worksheet_Change()
function:

Private Sub Worksheet_Change(ByVal Target As Range)

MsgBox CStr(Target.Address(0, 0))

End Sub


Now, if you enter data into cell N10 on the spreadsheet,
the message box will return with "N10". However, if you
DELETE the contents of cell N10, then the message box
will say "N10:P10". Why is this?? How can I tell
the "Target" variable to just give me "N10" string???
(I guess I'm too lazy to write code that parses range
strings, haha)

Thanks!



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Worksheet_Change() and range question

That works great. I was just hoping to avoid string operations
in my Worksheet_Change() function because string operations
might slow down my current VBA code.

Rather than using the code below, doesn't VBA have any
range functions to test if a Range object only contains ONE
cell address?? Or is there a built in function that returns exactly
how many cell addresses are in a Range object??



"Mike H" wrote in message
...
Robert,

It's not that big a job to check if there's a colon

Private Sub Worksheet_Change(ByVal Target As Range)
If InStr(Target.Address(0, 0), ":") 0 Then
MsgBox Left(Target.Address(0, 0), InStr(Target.Address(0, 0), ":") - 1)
Else
MsgBox Target.Address(0, 0)
End If
End Sub

Mike




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Worksheet_Change() and range question

If you are still talking about the merged cells, then you need to get the
count for the number of merged cells for the given cell reference. For
example, assuming we are still in the Worksheet Change event procedure...

MsgBox Target.MergeArea.Count

Otherwise replace Target with the cell reference; for example...

MsgBox Cells(1, "A").MergeArea.Count

--
Rick (MVP - Excel)


"Robert Crandal" wrote in message
...
That works great. I was just hoping to avoid string operations
in my Worksheet_Change() function because string operations
might slow down my current VBA code.

Rather than using the code below, doesn't VBA have any
range functions to test if a Range object only contains ONE
cell address?? Or is there a built in function that returns exactly
how many cell addresses are in a Range object??



"Mike H" wrote in message
...
Robert,

It's not that big a job to check if there's a colon

Private Sub Worksheet_Change(ByVal Target As Range)
If InStr(Target.Address(0, 0), ":") 0 Then
MsgBox Left(Target.Address(0, 0), InStr(Target.Address(0, 0), ":") - 1)
Else
MsgBox Target.Address(0, 0)
End If
End Sub

Mike



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Worksheet_Change() and range question

It seems like my problem is more complicated than I first realized.
I initially assumed that users would be deleting data from single
cells, but now I realize they could be deleting data from a
huge area that includes merged and un-merged cells.

Is it possible to structure my Worksheet_Change() function
into a "Select Case" statement in the following manner:

Select Case Target ' ???

' Case "Dated edited/changed in single cell"

' Case "Data deleted from single cell"

' Case "Data deleted from merged cells"

' Case "Data deleted from block containing merged & unmerged cells

' Case Else:

End Select:

How would you re-write the above pseudo-code into VBA code?

As always, thank you for your great help.


"Rick Rothstein" wrote in message
...
If you are still talking about the merged cells, then you need to get the
count for the number of merged cells for the given cell reference. For
example, assuming we are still in the Worksheet Change event procedure...

MsgBox Target.MergeArea.Count

Otherwise replace Target with the cell reference; for example...

MsgBox Cells(1, "A").MergeArea.Count


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Worksheet_Change() and range question

I think I was able to solve my own problem. I could structure
my Worksheet_Change() function as follows:

Select Case Target.Count

Case 1: ' ONE cell was edited/deleted
'
' Do stuff
'
Case Else: ' MANY cells were edited/deleted
'
' Do stuff
'
End Select

That would probaly work eh?


"Robert Crandal" wrote in message
...

Select Case Target ' ???

' Case "Dated edited/changed in single cell"

' Case "Data deleted from single cell"

' Case "Data deleted from merged cells"

' Case "Data deleted from block containing merged & unmerged cells

' Case Else:

End Select:

How would you re-write the above pseudo-code into VBA code?

As always, thank you for your great help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet_change question אלי Excel Programming 1 April 27th 09 07:35 AM
Newbie question regarding using Sub Worksheet_change() titus Excel Programming 2 August 30th 06 04:16 AM
worksheet_change question HRman Excel Programming 2 March 30th 06 05:35 PM
Excel VBA .... Worksheet_Change(ByVal Target As Range) question Joseph Donnelly Excel Programming 2 May 17th 04 08:35 PM
Worksheet_Change event question marwan hefnawy Excel Programming 1 September 10th 03 08:53 PM


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"