Forum Discussion
Jyggalag77
Aug 11, 2022Copper Contributor
Conditionally merge cells based on number?
Hi all, I want my cell to be merged like this (see attached photo). What defines my data is that there is always an age, so I would like to have, for example, a formula where once a number en...
- Aug 11, 2022
Sub merge() Dim i As Long Dim x As Variant Dim result As String Dim k As Long Dim m As Long Range("B:B").Clear m = Range("A" & Rows.Count).End(xlUp).Row k = 3 For i = 3 To m x = Right(Cells(i, 1), 1) If IsNumeric(x) Then Cells(k, 2).Value = Trim(result & " " & Cells(i, 1).Value) k = k + 1 result = "" Else result = Trim(result & " " & Cells(i, 1).Value) End If Next i End Sub
Maybe with this code. In the attached file you can click the button in cell D2 to run the macro.
OliverScheurich
Aug 11, 2022Gold Contributor
Sub merge()
Dim i As Long
Dim x As Variant
Dim result As String
Dim k As Long
Dim m As Long
Range("B:B").Clear
m = Range("A" & Rows.Count).End(xlUp).Row
k = 3
For i = 3 To m
x = Right(Cells(i, 1), 1)
If IsNumeric(x) Then
Cells(k, 2).Value = Trim(result & " " & Cells(i, 1).Value)
k = k + 1
result = ""
Else
result = Trim(result & " " & Cells(i, 1).Value)
End If
Next i
End Sub
Maybe with this code. In the attached file you can click the button in cell D2 to run the macro.
Jyggalag77
Aug 11, 2022Copper Contributor
Dear Quadruple_Pawn,
This is absolutely amazing! I simply do not know how to thank you enough for this 🙂
You have truly saved my day. Thank you so much sir!
If you have the spare time, I would love to get a breakthrough of what each section of the code does so I can understand it (if you can add notes to it maybe?). Otherwise, your help has truly been appreciated!!!
Thank you very much for this!!!
This is absolutely amazing! I simply do not know how to thank you enough for this 🙂
You have truly saved my day. Thank you so much sir!
If you have the spare time, I would love to get a breakthrough of what each section of the code does so I can understand it (if you can add notes to it maybe?). Otherwise, your help has truly been appreciated!!!
Thank you very much for this!!!