Sub CombineSelectedCells_Horizontally()
'***************************************************************************************
' Written By: AnotherHiggins
' Written On: 2007-08-12
' Purpose: Combine selected cells with all populated cells to the right of them
'***************************************************************************************
Dim strMsgPrompt As String
Dim strMsgTitle As String
Dim strInputPrompt As String
Dim strInputTitle As String
Dim MyResponse
Dim strMyDelimiter As String
Dim dblTtlRows As Double
Dim dblTtlCols As Double
Dim dblLstCol As Double
Dim dblActvCol As Double
' Strings for prompts
'*****************************************************
strMsgPrompt = Chr(9) & "This action cannot be undone!" & _
Chr(10) & _
Chr(10) & "You are about to combine cells in all selected rows." & _
Chr(10) & _
Chr(10) & "Are you sure you want to continue?"
strMsgTitle = "Combine Cells Alert!"
strInputPrompt = "Please type in what character(s), if any," & _
Chr(10) & "you would like inserted between cell values." & _
Chr(10) & "A popular choice is a comma followed by a space ("", "")" & _
Chr(10) & _
Chr(10) & "If you do not want any text inserted," & _
Chr(10) & "you can just leave the box empty."
strInputTitle = "Delimiter Input"
' Ask user to confirm before proceeding
'*****************************************************
MyResponse = MsgBox(strMsgPrompt, vbYesNo + vbDefaultButton2, strMsgTitle)
If MyResponse = vbNo Then GoTo AnsweredNo
' Ask user for a delimiter
'*****************************************************
strMyDelimiter = InputBox(strInputPrompt, strInputTitle)
' Find column information
'*****************************************************
dblTtlRows = ActiveSheet.Rows.Count
dblTtlCols = ActiveSheet.Columns.Count
dblLstCol = Cells.Find( _
What:="*", _
After:=Cells(dblTtlRows, dblTtlCols), _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
dblActvCol = ActiveCell.Column
' Disable screen updating to eliminate flicker
'*****************************************************
Application.ScreenUpdating = False
' Combine cell-contents horizontally for selection
'*****************************************************[highlight]
For Each rCell In Selection
For i = 1 To dblLstCol - dblActvCol
rCell.Value = rCell.Value & strMyDelimiter & rCell.Offset(, i).Value
rCell.Offset(, i).Clear
Next i
Next rCell[/highlight]
' Get rid of any leading or trailing spaces
' as well as duplicated spaces within text
'*****************************************************
Selection.Value = Application.Trim(Selection.Value)
Application.ScreenUpdating = True
AnsweredNo:
End Sub