Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Excel 97/2003 VBA merged cells

Hello

I have a problem which appears to be to do with the different ways in
which Excel 97 and 2003 treat merged cells.


In an Excel 2003 worksheet cell G5 is merged from 4 cells (G5:J5)

The following Excel 2003 VBA code works well ("OPS" is a named range
for cell G5):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Cells.Count = 1 Then 'do nothing if more than one cell is
changed

If Target.Address = Range("OPS").Address Then
'do stuff

'rest of code cut

End If

End If

End Sub


The code fails in Excel 97. Stepping through the code reveals that
Target.Cells.Count is equal to 4 and likewise Target.Address is equal
to "$G$5:$J$5".

Is there anything I can do about this other than to check which version
of Excel is running? Any other coding suggestions welcome.
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Excel 97/2003 VBA merged cells

Maybe something like this untested pseudo code. You will need to test an
approach like this to see what works the way you want.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Cells.Count < 1 Then 'do nothing if more than one cell is
if Target(1).MergeArea.Address < Target.Address then
exit sub
else
set rng = Target(1)
end if
Else
set rng = Target
End if

If rng.Address = Range("OPS").Address Then
'do stuff

'rest of code cut

End If

End If

--
Regards,
Tom Ogilvy


"Tony James" wrote:

Hello

I have a problem which appears to be to do with the different ways in
which Excel 97 and 2003 treat merged cells.


In an Excel 2003 worksheet cell G5 is merged from 4 cells (G5:J5)

The following Excel 2003 VBA code works well ("OPS" is a named range
for cell G5):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Cells.Count = 1 Then 'do nothing if more than one cell is
changed

If Target.Address = Range("OPS").Address Then
'do stuff

'rest of code cut

End If

End If

End Sub


The code fails in Excel 97. Stepping through the code reveals that
Target.Cells.Count is equal to 4 and likewise Target.Address is equal
to "$G$5:$J$5".

Is there anything I can do about this other than to check which version
of Excel is running? Any other coding suggestions welcome.
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Excel 97/2003 VBA merged cells

Try -

If Target.Count = Target(1).MergeArea.Count Then

Regards,
Peter T

"Tony James" wrote in message
ups.com...
Hello

I have a problem which appears to be to do with the different ways in
which Excel 97 and 2003 treat merged cells.


In an Excel 2003 worksheet cell G5 is merged from 4 cells (G5:J5)

The following Excel 2003 VBA code works well ("OPS" is a named range
for cell G5):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Cells.Count = 1 Then 'do nothing if more than one cell is
changed

If Target.Address = Range("OPS").Address Then
'do stuff

'rest of code cut

End If

End If

End Sub


The code fails in Excel 97. Stepping through the code reveals that
Target.Cells.Count is equal to 4 and likewise Target.Address is equal
to "$G$5:$J$5".

Is there anything I can do about this other than to check which version
of Excel is running? Any other coding suggestions welcome.
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Excel 97/2003 VBA merged cells

Tom and Peter, many thanks for your suggestions. I'll try your code
when I return to work tomorrow, they both look better than coding for
different Excel versions.

Thanks
Tony

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
Auto Numbering a merged Cells Excel 2003 Ommm Excel Discussion (Misc queries) 8 February 5th 09 02:40 AM
How can I sort an Excel Doc containing merged & non-merged cells? KellyH Excel Discussion (Misc queries) 11 June 10th 08 04:12 AM
2003: Autofit merged cells David M. Marcovitz Excel Discussion (Misc queries) 4 June 3rd 08 04:42 PM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
(2003) Pasting into merged cells Therapistmatt Excel Worksheet Functions 3 March 6th 07 06:42 PM


All times are GMT +1. The time now is 05:55 PM.

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

About Us

"It's about Microsoft Excel"