-Outlook 2003-
Hi all,
I have a macro stored in personal.xls. Someone usually sends me an excel list with a different number of users and they ask me if any of my users are in the list. The code runs the whole sheet, copies and pastes values all the data, searches for each of the names listed, and if found, replaces the value with the same value and colors the text. I have a macro that runs now but I would like to make it more efficient if possible:
' Sub routine, copies and pastes special to ensure formulas aren't searched.
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
'
Cells.Select
With Application.ReplaceFormat.Font
.FontStyle = "Bold"
.Subscript = False
.ColorIndex = 4
End With
Selection.Replace What:="UserName1", Replacement:="UserName1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
Selection.Replace What:="UserName2", Replacement:="UserName2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
... (repeated for each user name)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
'
Cells.Select
With Application.ReplaceFormat.Font
.FontStyle = "Bold"
.Subscript = False
.ColorIndex = 3
End With
Selection.Replace What:="First Last1", Replacement:="First Last1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
Selection.Replace What:="First Last2", Replacement:="First Last2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
... (repeated for each first and last name)
End Sub
The issues that I see that could happen:
-Currently there are 28 people which means the above code is repeated about 50 times. More people may get added to my list which will make the code even longer and it doesnt seem very efficient
-I also may want to change the search so if someone sends me a list with last name,first name or last name only, the cell will show up. But that would mean copying and pasting the text another 30-60 times
Is there any way to combine the data? Please let me know if I can make this any clearer.
This was also cross posted on the mrexcel forums:
http://www.mrexcel.com/forum/showthread.php?t=359526
Bookmarks