Cell Format Object

Represents both the FindFormat and ReplaceFormat property settings of the Application object, which are then used by the Find and Replace methods (respectively) of the Range object.

Set the FindFormat property settings before using the Find method to search for cell formats within a range. Set the ReplaceFormat property settings if you want the Replace method to replace formatting in cells. Any values specified in the What or Replacement arguments of either the Find or Replace methods will involve an And condition. For example, if you are searching for the word Wrox and have set the FindFormat property to search for Bold, only those cells containing both will be found.

When searching for formats, make sure the SearchFormat argument of the Find method is set to True. When replacing formats, make sure the ReplaceFormat argument of the Replace method is set to True.

When you want to search for formats only, make sure the What argument of the Find method contains nothing. When you only want to replace formats, make sure the Replace argument of the Replace method contains nothing.

When replacing one format with another, make sure you explicitly specify formats you no longer want. For example, if you are searching for cells containing both bold and red and want to replace both formats with just blue, you'll need to make sure you set the bold property of the ReplaceFormat property to False. If you don't, you'll end up with blue and bold text.

When you need to search or replace using different format settings (or none at all), be sure to either use the Clear method of the CellFormat object—if you've declared a variable as such — or directly access the Clear methods of the FindFormat and ReplaceFormat properties. Setting the SearchFormat and ReplaceFormat arguments to False for the Find and Replace methods will not prevent the FindFormat and/or ReplaceFormat settings from being used.

0 0

Post a comment