PDA

View Full Version : [SOLVED] How to Add Different Texts to End of Excel Cells Macro



BINJONE
11-03-2019, 03:08 AM
The following macro adds text to end of excel cell that you select. But its not very user friendly because you have every time to change the text that you want to add.
I wonder if we can add a line in the code that asks the users which text they want to add and in which cells in the end of every cell they choose
Sub AppendToExistingOnLeft()
Dim c As Range
Set mR = Application.InputBox("Select your Text", , , , , , , 8)
If mR Is Nothing Then MsgBox "Nothing Selected!", vbExclamation: Exit Sub
On Error GoTo 0
For Each c In Selection
If c.Value <> "" Then c.Value = "## " & c.Value
Next
End Sub

paulked
11-03-2019, 03:57 AM
Something like this?



Option Explicit


Sub AppendToExistingOnLeft1()
Dim c As Range, mR As Range, txt As String, yn As String
Set mR = Application.InputBox("Select your Text", , , , , , , 8)
If mR Is Nothing Then MsgBox "Nothing Selected!", vbExclamation: Exit Sub
On Error GoTo 0
txt = InputBox("Please enter the text you want to add...", "Enter text...")
yn = MsgBox("Add this text to the beginning? (If no, it will be added to the end!)", vbYesNo, "Where to add text...")
For Each c In mR
If yn = vbYes Then
If c.Value <> "" Then c.Value = txt & " " & c.Value
Else
If c.Value <> "" Then c.Value = c.Value & " " & txt
End If
Next
End Sub

BINJONE
11-03-2019, 04:05 AM
Thanks for the help!! It works

paulked
11-03-2019, 04:39 AM
:thumb You can mark this solved (Thread tools, top right)