ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   .find help (https://www.excelbanter.com/excel-programming/343315-find-help.html)

Wylie C

.find help
 
I have the following code that works fine. What I would like to know, is
there a way to write the For each wks....Next wks statement to set more than
one font attribute at a time? My code finds the cell then only sets the font
name. Can I set the font bold and italic at the same time? How can I code
this different to make it work the way I want?

Thank you.

Private Sub Testing()
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error GoTo quit
wks.Cells.Find(What:="test", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False).Font.Name = "Times
New Roman"
Next wks
quit:
Exit Sub
End Sub


Norman Jones

.find help
 
Hi C,

See VBA help on the Find method.

Adapting the given example to your requirements, try:

'============
Sub Tester01()
Dim wks As Worksheet
Dim c As Range
Dim firstAddress As String
Const sStr As String = "test" '<<==== CHANGE

For Each wks In ActiveWorkbook.Worksheets

With wks.Cells
Set c = .Find(sStr, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
With c.Font
.Bold = True
.Italic = True
End With

Set c = .FindNext(c)
Loop While Not c Is Nothing _
And c.Address < firstAddress
End If
End With
Next wks

End Sub
'<<============

---
Regards,
Norman



"Wylie C" wrote in message
...
I have the following code that works fine. What I would like to know, is
there a way to write the For each wks....Next wks statement to set more
than
one font attribute at a time? My code finds the cell then only sets the
font
name. Can I set the font bold and italic at the same time? How can I code
this different to make it work the way I want?

Thank you.

Private Sub Testing()
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error GoTo quit
wks.Cells.Find(What:="test", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlWhole, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False).Font.Name =
"Times
New Roman"
Next wks
quit:
Exit Sub
End Sub





All times are GMT +1. The time now is 02:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com