মঙ্গলবার, ২১ মার্চ, ২০১৭

How to append something before or after any text in MS Excel

  • Step 1: Select the range in which you will add specified text.
  • Step 2: Press Alt + F11 keys in Excel and it opens the Microsoft Visual Basic for Application window.
  • Step 3: Click Insert > Module, and paste the following VBA code in the Module Window.
VBA for adding specified text at the beginning of each cell

            Sub Func()
            Dim c As Range
            For Each c In Selection
            If c.Value<> "" Then c.Value="--textToappend--"&c.Value
            Next
            End Func


VBA for adding specified text at the end of each cell


           Sub Func()
           Dim c As Range
           For Each c In Selection
           If c.Value<> "" Then c.Value=c.Value & "--textToAppend--"
           Next
           End Func