02-28-2004, 08:17 AM
Join Date: Mar 2003
Location: Östersund Sweden
There are certains good coding-practice that the macro-recorder don´t take into consideration which also imply that You should only use it if You need to find out more about specific objects, properties and methods.
Below You find a example and You should always make sure that You use vriables and explicit declare all the variables. In that way You also avoid to increase the number of dots when working with the objects and so on. In that way the impact of the performance will increase.
As herilane pointed out: There is no need to select the objects we would like to work with.
Personally I prefer, at least in public forums like Extrema, to use the hierarchy of the objects in use. In that way we can also achieve a better understanding of the structure and how objects are related to each others.
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnCheck As Range, rnFind As Range
Dim stAddress As String
Set wbBook = ActiveWorkbook
Set wsSheet = wbBook.ActiveSheet
Set rnCheck = .Range("1:1")
Set rnFind = .Find(What:="XL-Dennis", LookIn:=xlValues, lookat:=xlWhole)
If Not rnFind Is Nothing Then
stAddress = rnFind.Address
rnFind.Font.Bold = True
Set rnFind = .FindNext(rnFind)
Loop While Not rnFind Is Nothing And rnFind.Address <> stAddress
Good luck with Your coding!