There are a few ways to do this. Here's an example:
Dim lRow As Long, lLastRow As Long
Dim rngToInsert As Range
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
For lRow = 2 To lLastRow
With Cells(lRow, 1)
If .Value2 <> .Offset(1).Value2 Then
If rngToInsert Is Nothing Then
Set rngToInsert = .Offset(1)
Set rngToInsert = Application.Union(rngToInsert, .Offset(1, lRow Mod 2))
If Not rngToInsert Is Nothing Then
Application.ScreenUpdating = False
Application.ScreenUpdating = True
You can adapt it as necessary: for example, you can add more criteria to determine whether or not a row needs to be inserted.
If you want any of the code or logic explained then please ask.
Insert a line break within the cell at the end of the text
First I like to thank you.
I am new to excel macro. I am looking for a solution which is time-sensitive.
Issue: I like to have a line break at the end of the last character of the text within the cell of the excel file.I want to apply the line break for entire column not just one cell. Can I know the VBA code for it?