merging cells using VB - Excel 2003

  • Thread starter Thread starter Carrie
  • Start date Start date
C

Carrie

I have a row of 1's and 0's. I would like to merge all the cells with 1's
that are grouped in a row and not merge the 0's.

Example:

1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1

So that the cells with 1's in them merge and the cells with 0's in them do
not merge.

Is is possible?

Thanks in advance
Carrie
 
Sub MergeCells()
RowCount = ActiveCell.Row

ColCount = 1
Do While Cells(RowCount, ColCount) <> ""
If Cells(RowCount, ColCount) = 1 Then
StartCol = ColCount
Data = 1
Do While Cells(RowCount, ColCount) = 1 And _
Cells(RowCount, (ColCount + 1)) = 1

ColCount = ColCount + 1
Data = Data & " 1"
Loop
Range(Cells(RowCount, StartCol), _
Cells(RowCount, ColCount)). _
MergeCells = True
Cells(RowCount, StartCol) = Data
End If

ColCount = ColCount + 1
Loop
 

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