Looping problem

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm trying to loop through a range (G6 to G40). I'm looking at each cell and determing if the cell in the same row, but the next column(H) has a "-". If so I need the cell in column G, and all like them in the range to be Bold.

For example

col G col H
A -
B 2
A 5
C 3

In this scenario, Both A's should be bolded.

I've been struggling with this. Any ideas?

Thanks,

Dave
 
I'm trying to loop through a range (G6 to G40). I'm looking at each cell and determing if the cell in the same row, but the next column(H) has a "-". If so I need the cell in column G, and all like them in the range to be Bold.

For example

col G col H
A -
B 2
A 5
C 3

In this scenario, Both A's should be bolded.

I've been struggling with this. Any ideas?

The code below should get go started.

Option Explicit
Sub DB()
Dim lngCount As Long
Dim rngCell As Range
Dim rngCell2 As Range

For Each rngCell In Range("G6:G40")
If rngCell.Offset(0, 1) = "-" Then
rngCell.Font.Bold = True
lngCount = lngCount + 1
For Each rngCell2 In Range(rngCell.Offset(1, 0), "G40")
If rngCell2 = rngCell Then
rngCell2.Font.Bold = True
lngCount = lngCount + 1
End If
Next rngCell2
End If
Next rngCell
MsgBox lngCount & " cell(s) bolded.", vbInformation + vbOKOnly, "DB"
End Sub
 
Il giorno mercoledì 21 novembre 2012 23:22:35 UTC+1, Dave ha scritto:
I'm trying to loop through a range (G6 to G40). I'm looking at each cell and determing if the cell in the same row, but the next column(H) has a "-".. If so I need the cell in column G, and all like them in the range to be Bold.
For example
col G col H
A -
B 2
A 5
C 3
In this scenario, Both A's should be bolded.

Hi Dave.

Go to G6 then:
Home|Conditional Formatting
New Rule...
Use a formula to determine which cells to format
Format values where this formula is true:
=SUM(--($G6&"0"=$G$6:$G$40&$H$6:$H$40))
-OR-
=SUM(--($G6&"-"=$G$6:$G$40&$H$6:$H$40))
Format...
Font style: Bold
OK
OK
Home|Conditional Formatting
Manage Rules...
Applies to
=$G$6:$H$40
OK
 
Back
Top