Set certain rows to Bold

  • Thread starter Thread starter jerry chapman
  • Start date Start date
J

jerry chapman

I want to step through all the used rows, and for those rows that have a
certain string contained in column B I want to set the row to bold. How
could I write a macro to do that?
 
Look in vba HELP for FINDNEXT. There is an excellent example you can modify
 
I looked in vba help for findnext, and it talked about a record set. I don't
see the relevenct to my question.
 
Wrong FindNext. Here is the example code referred to:

Example
This example finds all cells in the range A1:A500 that contain the value 2
and changes their values to 5.

With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
 
I don't think that really addresses my problem. I had simplified it a
little. So let me restate it.
I want to work on each row individually. In each row I want to check for a
different sequence of character in three different column. If the required
sequence is found in any of the three columns, I want to set all the columns
in that to Bold.
 
Ahhh. But you could use that shell to seach through each of the 3 columns. If
you find a match, you just bold the row.

Option Explicit
Sub testme01()

Dim myCols As Variant
Dim iCtr As Long
Dim WhatToFind As Variant
Dim c As Range
Dim FirstAddress As String

myCols = Array("a", "E", "J")
WhatToFind = Array("abcd", "efgh", "ijkl")


For iCtr = LBound(myCols) To UBound(myCols)
FirstAddress = ""
With Worksheets("sheet1").Range(myCols(iCtr) & "1").EntireColumn
Set c = .Cells.Find(what:=WhatToFind(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
lookat:=xlPart, _
searchdirection:=xlNext)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
c.EntireRow.Font.Bold = True
Set c = .FindNext(c)
Loop While Not c Is Nothing _
And c.Address <> FirstAddress
End If
End With
Next iCtr
End Sub

Watch out for that .find command. I looked for it in any part of the cell
(xlpart vs xlwhole).

You could cycle through each of the rows and use instr() to look for a match,
but .find's can be a lot faster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top