Mister_joe
12-03-2013, 03:50 AM
Hi All,
It is my first time here. I am also just starting to learn VBA. The code snippet below was copied from the Excel Help.
Sub ChangeCellFormat() ' Set the interior of cell A1 to yellow.
Range("A1").Select
Selection.Interior.ColorIndex = 36
MsgBox "The cell format for cell A1 is a yellow interior."
' Set the CellFormat object to replace yellow with green.
With Application
.FindFormat.Interior.ColorIndex = 36
.ReplaceFormat.Interior.ColorIndex = 35
End With
' Find and replace cell A1's yellow interior with green.
ActiveCell.Replace What:="", Replacement:="", lookAt:=xlPart, MatchCase:=False, SearchOrder:=xlByRows, SearchFormat:=True, ReplaceFormat:=True
MsgBox "The cell format for cell A1 is replaced with a green interior."
End Sub
The code does not work as expected. I do not seem to understand how the resulting CellFormat object has a connection with the Replace method. Can you clarify it for me, please.
It is my first time here. I am also just starting to learn VBA. The code snippet below was copied from the Excel Help.
Sub ChangeCellFormat() ' Set the interior of cell A1 to yellow.
Range("A1").Select
Selection.Interior.ColorIndex = 36
MsgBox "The cell format for cell A1 is a yellow interior."
' Set the CellFormat object to replace yellow with green.
With Application
.FindFormat.Interior.ColorIndex = 36
.ReplaceFormat.Interior.ColorIndex = 35
End With
' Find and replace cell A1's yellow interior with green.
ActiveCell.Replace What:="", Replacement:="", lookAt:=xlPart, MatchCase:=False, SearchOrder:=xlByRows, SearchFormat:=True, ReplaceFormat:=True
MsgBox "The cell format for cell A1 is replaced with a green interior."
End Sub
The code does not work as expected. I do not seem to understand how the resulting CellFormat object has a connection with the Replace method. Can you clarify it for me, please.