Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default How to check for Horizontally merged cells

In my spreadsheet, users are allowed to merge cells in a single
column, but not across rows.

How can I check (in VBA) that the selection contains either a single
cell, or a merged block in a column, and allow the process to
continue, but if the selection contains cells merged across rows, then
present an error message and stop.

Many thanks.

Rick

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to check for Horizontally merged cells

This worked ok for me in xl2003:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim ErrorInMergedCells As Boolean

Set myRng = Selection

ErrorInMergedCells = False
If myRng.Cells.Count = 1 Then
'everything's ok?
ElseIf myRng.MergeCells = False Then
'no merged cells in selection, don't test anything
'true means that the selection consists of merged cells
'null means that the selection has a mixture of
'merged cells and non-merged cells
Else
For Each myCell In myRng.Cells
If myCell.MergeCells Then
If myCell.MergeArea.Columns.Count 1 Then
ErrorInMergedCells = True
MsgBox "You have merged cells across columns " _
& "in the selection." & vbLf & _
"Like: " & myCell.Address & _
" merged across columns " & myCell.MergeArea.Address
Exit For
End If
End If
Next myCell
End If

If ErrorInMergedCells Then
'do nothing
Else
'do the real work??
End If

End Sub

APP OEU wrote:

In my spreadsheet, users are allowed to merge cells in a single
column, but not across rows.

How can I check (in VBA) that the selection contains either a single
cell, or a merged block in a column, and allow the process to
continue, but if the selection contains cells merged across rows, then
present an error message and stop.

Many thanks.

Rick


--

Dave Peterson
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
how do i link merged cells to a merged cell in another worksheet. ibbm Excel Worksheet Functions 3 April 27th 06 11:40 PM
how to align vertical cells horizontally Trice New Users to Excel 1 October 12th 05 05:42 PM
How to copy cells horizontally to cells out of sequence brantty Excel Discussion (Misc queries) 3 October 9th 05 05:35 AM
Move cells vertically to horizontally Abe Excel Discussion (Misc queries) 1 March 23rd 05 02:57 AM
Sorting merged cellsHow do I sort merged cells not identically siz Laval Excel Worksheet Functions 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 03:25 AM.

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"