Cell Selection issue

S

Steve

Morning all.
I'm making a user form, and want to select a cell to place my equation, then
with that selection choice, offset upwards, and to the side, to select and
merge two sets of two cells, each.

I understand with my selection that I'd use the following:
activecell.offset(0,1).select
to get my first cell selection.
But how do I retain that initial selection, and then offset one more up, to
then merge those two cells?

Thank you.
 
R

Ryan H

I'm not 100% sure what you are wanting but I think you want to merge the cell
to the right of the activecell with the cell one row above that cell, right?
If so, you can use this line of code.

Union(ActiveCell.Offset(0, 1), ActiveCell.Offset(-1, 1)).MergeCells = True

Hope this helps! If so, let me know, click "YES" below.
 
S

Steve

Hi Ryan,
Sorry that it wasn't clear enough.
I want to select one cell, and then merge the one above, with that cell--
merging two cells in the same column, together.
I then want to offset one column to the right, and merge two cells together.
My issue is how do I <select the two cells in the single column> to merge
them?

Thank you.
 
R

Ryan H

In order to select merged cells you have to reference the entire range
address. For example:

To select a single cell you would use Range("A1").Select

If A1 and A2 were merged you use Range("A1:A2").Select

Here are a few lines of code you can use:

' merge the active cell and cell above active cell
Union(ActiveCell, ActiveCell.Offset(-1, 0)).MergeCells = True

' merge the cell right of active cell and cell above that cell
Union(ActiveCell.Offset(0, 1), ActiveCell.Offset(-1, 1)).MergeCells = True

' select merged cells to the right of active cell
Range(Cells(ActiveCell.Row, ActiveCell.Column + 1), Cells(ActiveCell.Row
- 1, ActiveCell.Column + 1)).Select

Hope this helps! If so, let me know, click "YES" below.
 

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

Top