HI
My issue is it only replaces all instances on the ActiveSheet
oSht.Cells should allow it to work on all cells on oSht
Short Version
Change:
into
Yet still work
It would be a lot neater if I could make replace work without the sheet being "made over" being active.
Without the Activate it only replaces all instances on the ActiveSheet
I'm sure I've done this many times in the past
The Project version
I have 3 columns
1 contains "Old Values"
2 contains "New Values"
3 Boolean TRUE Old = New, FALSE if different.
If they are different (Col3 = FALSE) I want to replace all occurrences in all cells on every worksheet with the new values.
Seems simple enough.
Cells refers to Cells on Activesheet so we need to loop through the sheets and apply replace
This should work fine only doesn't unless we make the sheet active.
Why the need OR how to make it work without activate?...
Quick & Dirty code follows
My issue is it only replaces all instances on the ActiveSheet
oSht.Cells should allow it to work on all cells on oSht
Short Version
Change:
VBA Code:
For Each oSht In ThisWorkbook.Worksheets
oSht.Activate
oSht.Cells.Replace What....
into
VBA Code:
For Each oSht In ThisWorkbook.Worksheets
oSht.Cells.Replace What....
It would be a lot neater if I could make replace work without the sheet being "made over" being active.
Without the Activate it only replaces all instances on the ActiveSheet
I'm sure I've done this many times in the past
The Project version
I have 3 columns
1 contains "Old Values"
2 contains "New Values"
3 Boolean TRUE Old = New, FALSE if different.
If they are different (Col3 = FALSE) I want to replace all occurrences in all cells on every worksheet with the new values.
Seems simple enough.
Cells refers to Cells on Activesheet so we need to loop through the sheets and apply replace
This should work fine only doesn't unless we make the sheet active.
Why the need OR how to make it work without activate?...
Quick & Dirty code follows
VBA Code:
Option Explicit
Sub CQSPartDesc_Adjust()
' Select all cells in the column flagging if the Part Desc Changed
' Looking for values FALSE (use a formula like =B4=J4)
' Then Run this code
Dim oCell As Range
Dim oShtOrig As Worksheet
Dim oSht As Worksheet
Dim strDescOld As String
Dim strDescNew As String
'Adjust these for correct Offset (old to the RHS in the instance used), Offsets relate to the Col with Flags!
Const cintColOffsetReplaceThis As Integer = 4 'Number of Columns offset Data to Replace
Const cintColOffsetReplaceWith As Integer = -4 'Number of Columns offset Data to Replace With
Application.ScreenUpdating = False
Set oShtOrig = ActiveSheet
For Each oCell In Selection.Cells
If oCell Then
GoTo getnext
Else
strDescOld = oCell.Offset(0, cintColOffsetReplaceThis).value
strDescNew = oCell.Offset(0, cintColOffsetReplaceWith).value
For Each oSht In ThisWorkbook.Worksheets
oSht.Activate
oSht.Cells.Replace What:=strDescOld, _
Replacement:=strDescNew, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next oSht
End If
getnext:
oShtOrig.Activate
Next oCell
Application.ScreenUpdating = True
End Sub