Excel Find and Replace: Help with Macro!

WolverineGator

Golden Member
Mar 20, 2001
1,011
0
76
This simply finds columns with "%" and formats all numbers below it to one significant digit after the decimal. I would like to to find columns with "%", "#", "Rate", etc. Right now I'm manually changing the What:="%" to the value I need. Is there a way to search for multiple values at the same time using an OR statement?

Cells.Find(What:="%", What:="Rate", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "0.0"

 

KLin

Lifer
Feb 29, 2000
30,958
1,082
126
So you want to do the following:

1. Look for a matching value in column headers
2. If match found, change the format of the cell to only one digit after the decimal for that column

Correct?
 

WolverineGator

Golden Member
Mar 20, 2001
1,011
0
76
Yes.
1. Look for matching value (one of several) in column header.
2. If match found, then do X (in this case change format).
 

GaryJohnson

Senior member
Jun 2, 2006
940
0
0
Does this work for you?

findArray = Array("%", "#", "Rate")

For Each value In findArray
Set found = Cells.Find(value)
If Not found Is Nothing Then
Set firstFound = found
Do
Range(found, found.End(xlDown)).NumberFormat = "0.0"
Set found = Cells.FindNext
Loop Until found = firstFound
End If
Next value