Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get the cell to the right of a merged cell in VBA

1,319 views
Skip to first unread message

Marcel

unread,
Apr 29, 2009, 8:04:36 AM4/29/09
to
Hello,

In VBA I would like to find the cell to the right of a merged cell. (or its
column-number)
The column of the cell to the right is not just the column of the ActiveCell
+ 1, but it depends on who many columns are merged!

Example:

In row 1 Cell A and B are merged. (A1 and B1 are merged)

The user can select this merged cell. Its name is A1. (B1 is not existing,
as it is merged to A1).

In VBA find now the Column of the cell to the right. In the sheet it is C1.
(so VBA should give column=3 for C).

What is the code for this?

ActiveCell.Next gives 2, means "B", this is wrong, this cell is not
existing.


Thanks for any help
Marcel


Nigel

unread,
Apr 29, 2009, 8:27:37 AM4/29/09
to
Something like this will return the address of the next cell to the right of
a merged group of cells...

Range("A1").MergeArea.Offset(0, 1).Address

--

Regards,
Nigel
nigel...@9sw.co.uk

"Marcel" <MSch...@gmx.ch> wrote in message
news:49f84254$0$9117$5402...@news.sunrise.ch...

Per Jessen

unread,
Apr 29, 2009, 8:30:09 AM4/29/09
to
Hello Marcel,

This is what you need:

NextCol=ActiveCell.MergeArea.Offset(0, 1).Column

Regards,
Per

"Marcel" <MSch...@gmx.ch> skrev i meddelelsen
news:49f84254$0$9117$5402...@news.sunrise.ch...

Marcel

unread,
Apr 29, 2009, 12:44:30 PM4/29/09
to
Thanks,

But when I use "Delete" on the Merged Cell A1 (=A1+B1) I get an exception on
Range("A1").MergeArea.

But Range("A1").Offset(0, 1) works (without .MergeArea)

Marcel


"Nigel" <nige...@nosupanetspam.com> wrote in message
news:%23pqPjXM...@TK2MSFTNGP03.phx.gbl...

Marcel

unread,
Apr 29, 2009, 12:44:39 PM4/29/09
to
Thanks,

But when I use "Delete" on the Merged Cell A1 (=A1+B1) I get an exception on
Range("A1").MergeArea.

But Range("A1").Offset(0, 1) works (without .MergeArea)

Marcel
"Per Jessen" <per.j...@mail.dk> wrote in message
news:elHL8YMy...@TK2MSFTNGP06.phx.gbl...

Rick Rothstein

unread,
Apr 29, 2009, 2:06:07 PM4/29/09
to
It is not clear from your two posts what you are trying to do. My guess is
you want to delete the contents of the cell to the right of the merged
cells. If that is the case, then this works for me...

Range("A1").MergeArea.Offset(,1).Delete

--
Rick (MVP - Excel)


"Marcel" <MSch...@gmx.ch> wrote in message

news:49f883ee$0$9110$5402...@news.sunrise.ch...

Marcel

unread,
Apr 29, 2009, 3:49:07 PM4/29/09
to
Hello Rick,

The user Selects the (Merged) Cell "A1" and deletes its content. (with the
"delete" button on the keyboard).
This fires my function Workbook_SheetChange.
In this function I would like to know the column of the next cell to the
right, but my function makes an exception on the
second Line does an exception, first not!

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Debug.Print Target .Offset(0, 1).Column
Debug.Print Target .MergeArea.Offset(0, 1).Column ' here I get an
exception!!
end sub

Tkx
Marcel

"Rick Rothstein" <rick.new...@NO.SPAMverizon.net> wrote in message
news:eNQLtUPy...@TK2MSFTNGP06.phx.gbl...

0 new messages