Skip to content

Instantly share code, notes, and snippets.

@rdapaz
Forked from ricdeez/JoinCells.vb
Created June 21, 2018 09:45
Show Gist options
  • Save rdapaz/4bfc72443f216aa8819289186613c442 to your computer and use it in GitHub Desktop.
Save rdapaz/4bfc72443f216aa8819289186613c442 to your computer and use it in GitHub Desktop.
VBA: Join Cells on a Spreadsheet
Public Sub JoinCells()
Dim xls As Excel.Worksheet
Dim cell As Excel.Range
Dim destn_rge As Excel.Range
Dim combined As String
Dim i As Long
i = 0
Set destn_rge = Nothing
combined = ""
For Each cell In Selection
i = i + 1
If i = 1 Then
Set destn_rge = cell
End If
combined = combined & cell.Value & vbCrLf
Next cell
destn_rge.Value = combined
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment