• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to insert line break within a cell

ramindya

New Member
Hello,

To manually insert a line break at the end of the text of the cell in excel file the solution is "ALT + Enter." But I like to create a macro in the excel file which will do same but to the entire column in the excel file.

Please see the attached sample picture which will give an idea.

Thanks,
Ram
 

Attachments

  • sample.png
    sample.png
    10.3 KB · Views: 6

Hi ramindya !

Dim Rg as Range then use a For Each Rg structure to loop the range of cells
(see also property CurrentRegion) and on each cell Value add the line feed :

Rg.Value = Rg.Value & vbLf

Regards !
 
Hi,
I would use something like this.
Code:
Option Explicit

Sub InsertLine()
Dim Cell As Range, MyRange As Range

Set MyRange = Cells(1, 1).CurrentRegion ' change to suit your need

For Each Cell In MyRange
    Cell.Value = Cell.Value & Chr(10)
Next Cell

End Sub

With Regards
Rudra
 
Back
Top