Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default For Loop and If Statement question

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
for loop with if statement Steve Excel Worksheet Functions 1 February 17th 10 07:56 PM
On Error Resume Next (when next statement is Do Loop ...) EagleOne Excel Discussion (Misc queries) 2 September 26th 06 03:26 PM
If statement - Loop? George Excel Discussion (Misc queries) 1 March 14th 06 07:06 AM
For Loop and If Statement question jacqui[_2_] Excel Programming 4 February 13th 04 09:24 PM
Do Until loop with if statement Sandy[_3_] Excel Programming 4 July 17th 03 11:06 AM


All times are GMT +1. The time now is 09:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"