Hi There,
Could somebody assit me in amending the code below. Currently the code inserts a blank row then inserts the appropriate title text.
I would now like to make the inserted text bold and merge cells A - I in the inserted row. I just cannot get it to work
Thanks for any help
Sub InsertRows()
Dim r As Long, mcol As String, i As Long
' find last used cell in Column E
r = Cells(Rows.Count, "E").End(xlUp).row
' get value of last used cell in column A
mcol = Cells(r, 5).Value
' insert rows by looping from bottom
For i = r To 1 Step -1
If Cells(i, 5).Value <> mcol Then
Rows(i + 1).Insert
Cells(i + 1, 5).Value = PeriodTitle(mcol, i + 1)
mcol = Cells(i, 5).Value
End If
Next i
End Sub
Function PeriodTitle(ByRef period As String, row As Long) As String
Select Case Left(period, 2)
Case Is = "Q1"
PeriodTitle = "January - March " & Right(period, 4)
Case Is = "Q2"
PeriodTitle = "April - June " & Right(period, 4)
Case Is = "Q3"
PeriodTitle = "July - September " & Right(period, 4)
Case Is = "Q4"
CPeriodTitle = "October - December " & Right(period, 4)
Case Else
PeriodTitle = "Invalid Quarter in Row " & row + 1
End Select
End Function
Bookmarks