#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default .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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default .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



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
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
find and delete duplicate entries in two columns or find and prin. campare 2 columns of numbers-find unique Excel Programming 1 November 24th 04 04:09 PM
find and delete text, find a 10-digit number and put it in a textbox Paul Excel Programming 3 November 16th 04 04:21 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 02:11 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"