Thread: Macro help
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Macro help

Sub DoReplacements()
Dim sh as Worksheet
for each sh in worksheets
with sh
.Columns("C:C").Replace What:="x", Replacement:="1"
.Columns("D:D").Replace What:="x", Replacement:="2"
.Columns("E:E").Replace What:="x", Replacement:="3"
.Columns("F:F").Replace What:="x", Replacement:="4"
.Columns("G:G").Replace What:="x", Replacement:="5"
.Columns("H:H").Replace What:="x", Replacement:="6"
.Columns("I:I").Replace What:="x", Replacement:="7"
.Columns("J:J").Replace What:="x", Replacement:="8"
.Columns("K:K").Replace What:="x", Replacement:="9"
.Columns("L:L").Replace What:="x", Replacement:="10"
End with
Next
End Sub

Should work

--
Regards,
Tom Ogilvy


"Anne" wrote in message
...
I need to perform the same action on several dozen spreadsheets. I need

to
replace all the Xs in column C with 1s, column D with 2s, E with 3s, etc.

I
recorded a macro of my doing that for 10 columns (selecting the column,
replacing the text) . When I try and run the macro on the other
spreadsheets, it selects the whole spreadsheet and replaces the Xs with

1s.
I tried to cut out the pieces of code that I thought might be superfluous

and
currently have this:
Columns("C:C").Select
Selection.Replace What:="x", Replacement:="1"
Columns("D:D").Select
Selection.Replace What:="x", Replacement:="2"
Columns("E:E").Select
Selection.Replace What:="x", Replacement:="3"
Columns("F:F").Select
Selection.Replace What:="x", Replacement:="4"
Columns("G:G").Select
Selection.Replace What:="x", Replacement:="5"
Columns("H:H").Select
Selection.Replace What:="x", Replacement:="6"
Columns("I:I").Select
Selection.Replace What:="x", Replacement:="7"
Columns("J:J").Select
Selection.Replace What:="x", Replacement:="8"
Columns("K:K").Select
Selection.Replace What:="x", Replacement:="9"
Columns("L:L").Select
Selection.Replace What:="x", Replacement:="10"

Can anyone help? Thanks in advnace,
Anne