referring by index to adjacent cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I need to repeatedly select a cell by its index (e.g. Cells(r,1) with a loop
over r), and merge it with the cell to the right. Could you please tell me
how it can be done? (Can I select the cell, and then expand Selection to the
right?)
Thank you very much!
 
I assumed you meant to iterate through a range of cells
using a loop and to merge each of these cells with the
cell on the right. There is seldom a need to select cells.

Sub MergeCells()
Dim r As Integer
For r = 5 To 10
Cells(r, 1).Resize(1, 2).MergeCells = True
Next r
End Sub

Regards,
Greg
 
Use the Range selection and cells to select the anchor and the range extent.
So......

Range(Cells(r, c1), Cells(r, c2)).Select

where c1 = first column and c2 increments to extend range to the right.

Cheers
Nigel
 

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

Back
Top