Tech Support Guy banner

MACRO - To run on all worksheets

911 Views 1 Reply 2 Participants Last post by  Rollin_Again
(This is my first posting)

I'm very far from being macro knowledgeable, however, I did create two small macros that I would like to run on all worksheets, rather than just the active worksheet. And if possible, I'd like them to be the same macro, however, they seem to only work as two separate ones. I've found some code for looping the macro but I can't figure out how to add it to what I already have so that it will work. I'd really appreciate any help. See Below...


This is my first macro, it finds the line in the worksheet that says Grand Total, and then it replaces it new text that includes adding the text from part of another cell.

Sub GrandTotal()
'
' GrandTotal Macro
'

'
Cells.Replace What:="Grand Total", Replacement:= _
"=""Grand""&REPLACE(A6,1,FIND("": "",A6)+0,"""")&"" Total""", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
End Sub


This is my second macro, that finds the word 'Fee' and replaces it with 'Profit', if a cell contains specific text.


Sub FeetoProfit()

'Changes Fee to Profit if contract type in cell A6 says Firm Fixed Price

If (Range("A6") = "Contract Type: Firm Fixed Price") Then
Cells.Replace What:="Fee", Replacement:="Profit", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

End If

End Sub


Again, i want it to work on all the sheets in the workbook and if possible for them to be combined. Thanks so much!
See less See more
Status
Not open for further replies.
1 - 2 of 2 Posts
You just need to add a loop to select and process each sheet.

Code:
Sub ReplaceText()

For i = 1 To ActiveWorkbook.Sheets.Count

Sheets(i).Activate

Cells.Replace What:="Grand Total", Replacement:= _
"=""Grand""&REPLACE(A6,1,FIND("": "",A6)+0,"""")&"" Total""", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
End Sub

If (Range("A6") = "Contract Type: Firm Fixed Price") Then
Cells.Replace What:="Fee", Replacement:="Profit", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End If

Next i

End Sub
See less See more
1 - 2 of 2 Posts
Status
Not open for further replies.
Top