Consulting

Results 1 to 4 of 4

Thread: How to Add Different Texts to End of Excel Cells Macro

  1. #1
    VBAX Newbie
    Joined
    Nov 2019
    Posts
    2
    Location

    Lightbulb How to Add Different Texts to End of Excel Cells Macro

    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

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    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
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Newbie
    Joined
    Nov 2019
    Posts
    2
    Location
    Thanks for the help!! It works
    Last edited by BINJONE; 11-03-2019 at 04:23 AM.

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You can mark this solved (Thread tools, top right)
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •