J
jacqui
I have written the following sub which loops to test
whether a cell is in bold font. If this is true then I've
said insert a row. My code is below and I have three
questions.
Sub format_InsertRows()
Dim lngLastRow As Long
Dim i As Long
Worksheets("data").Select
With ActiveSheet
lngLastRow = .Cells(Rows.Count, 6).End(xlUp).Row
For i = 2 To lngLastRow
If .Cells(i, 6).Font.Bold = True Then .Cells(i,
6).EntireRow.Insert
Next
End With
End Sub
(1) My if statement inserts a row in the wrong place. I'd
like a row inserted AFTER the row in bold. How do I do
that without messing up my i counter? Do I use offset?
(2) Because my if statement inserts a row before the cell
in bold the same cell is then tested again and another row
inserted. I've tried working backwards using the step -1
but this wasn't very successful. I guess this can be
resolved as part of question 1.
(3) My data in the test cell is shown in three styles
not bold (do not insert row)
bold (insert row)
bold + italic (do not insert row)
how do I ensure that a row is inserted for the bold font
cells only, ie not the ones it finds in a bold + italic
font.
Does this make sense? Any help is appreciated.
Many thanks
Jacqui
whether a cell is in bold font. If this is true then I've
said insert a row. My code is below and I have three
questions.
Sub format_InsertRows()
Dim lngLastRow As Long
Dim i As Long
Worksheets("data").Select
With ActiveSheet
lngLastRow = .Cells(Rows.Count, 6).End(xlUp).Row
For i = 2 To lngLastRow
If .Cells(i, 6).Font.Bold = True Then .Cells(i,
6).EntireRow.Insert
Next
End With
End Sub
(1) My if statement inserts a row in the wrong place. I'd
like a row inserted AFTER the row in bold. How do I do
that without messing up my i counter? Do I use offset?
(2) Because my if statement inserts a row before the cell
in bold the same cell is then tested again and another row
inserted. I've tried working backwards using the step -1
but this wasn't very successful. I guess this can be
resolved as part of question 1.
(3) My data in the test cell is shown in three styles
not bold (do not insert row)
bold (insert row)
bold + italic (do not insert row)
how do I ensure that a row is inserted for the bold font
cells only, ie not the ones it finds in a bold + italic
font.
Does this make sense? Any help is appreciated.
Many thanks
Jacqui