victorcarreto
New Member
- Joined
- Jun 28, 2012
- Messages
- 7
I’ve a Macro to split a cell and shift cells down, as the following:
And, another macro to join cell bellow with the one above shifting cells up, as the following:
When I use these macros, the formula in column C (=Len(A1)-Len(B1) ) loses its reference (from the row I used the macro to below). Is there a way to add an update/refresh of the formula in column C, maybe adding some code to my macros that copy the formula in C1 to the rest of the cells in column C?
I’m also looking for a macro that would do this function itself (update/refresh the formula in column C).
Thank you!
Code:
[COLOR=#000000][FONT=Arial]Sub SplitCell()[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim s As String, v As Variant, l As Long[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]s = ActiveCell.Value[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]v = Split(s, vbLf)[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]l = UBound(v) - LBound(v) + 1[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]If l > 1 Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] ActiveCell.Offset(1, 0).Resize(l - 1, 1).Insert Shift:=xlShiftDown[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] ActiveCell.Resize(l, 1).Value = Application.Transpose(v)[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]End Sub[/FONT][/COLOR]
Code:
[COLOR=#000000][FONT=Arial]Sub JoinCellsMoveup()[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] If ActiveCell.Row > 1 Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] ActiveCell.Offset(-1, 0).Value = ActiveCell.Offset(-1, 0).Text & " " & ActiveCell.Text[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] ActiveCell.Delete[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]End Sub[/FONT][/COLOR]
I’m also looking for a macro that would do this function itself (update/refresh the formula in column C).
Thank you!