View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Merge Cells Logic

Hi; intially i though to merge th data. The below will merge the cells

Sub Macro()
Dim lngRow As Long, lngSRow As Long
For lngRow = 1 To Cells(Rows.Count, "B").End(xlUp).Row
If WorksheetFunction.IsText(Range("A" & lngRow)) Then
If lngSRow < 0 Then
Range("A" & lngSRow & ":A" & lngRow - 1).Cells.Merge
End If
lngSRow = lngRow
End If
Next
Range("A" & lngSRow & ":A" & lngRow).Cells.Merge
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Brian

Try the below macro..with your data in ColA. It should merge and writ the
data in ColB. Separator used is space. change if needed to suit your
requirement..

Sub Macro()
Dim lngRow As Long, lngNRow As Long, strData As String
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If WorksheetFunction.IsText(Range("A" & lngRow)) Then
If Trim(strData) < "" Then _
lngNRow = lngNRow + 1: Range("B" & lngNRow) = Trim(strData)
strData = Range("A" & lngRow)
Else
strData = strData & " " & Range("A" & lngRow)
End If
Next
Range("B" & lngNRow + 1) = Trim(strData)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Brian B" wrote:

Hello,
I would like to be able to go RowXRow/Column and merge Cells vertically
based on the conditions that the first cell has text content, and the
subsequent cells do not.

This selection would progress downward/column until another cell that
contains Text was encountered, and then the gathered selection previous to
that 2nd cell with text was encountered, would be merged.

I'm thinking I should use a Boolean to = True when cells contain content,
and False when they do not, and Select cells based around that toggle.

Obviously this logic is a bit tricky for me to handle, so any help is
appreciated.

Thanks,
Brian