Hi Guys,
I have a macro as per below;
Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long
fndList = Array("Wk 14", "Wk 15", "Wk 16", "Wk 17", "Wk14", "Wk15", "Wk16", "wk17")
rplcList = Array("Wk 18", "Wk 19", "Wk 20", "Wk 21", "Wk18", "Wk19", "Wk20", "wk21")
'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End Sub
This runs through a monthly workbook and updates values found within multiple formulas to the next month. My question however relates to the exclusion of a 5th week to the data. I believe there are 4, five week months this year. Is there a way I can accommodate this in my macro? Particularly if the formula that the above changes goes from requiring four values to five and vice versa. I can add the formula to the relevant cells, extending it to include 5 weeks of data where necessary but is there a way to do it, without manually adjusting the 4 & 5 week spreadsheets.
the formula example is below.
4 WEEKS =IF($J$2="Wk 18",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk18'!$A:$I,9,0),IF($J$2="Wk 19",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk19'!$A:$I,9,0),IF($J$2="Wk 20",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk20'!$A:$I,9,0),IF($J$2="Wk 21",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk21'!$A:$I,9,0),"Check"))))
5 WEEKS =IF($J$2="Wk 18",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk18'!$A:$I,9,0),IF($J$2="Wk 19",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk19'!$A:$I,9,0),IF($J$2="Wk 20",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk20'!$A:$I,9,0),IF($J$2="Wk 21",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk21'!$A:$I,9,0),IF($J$2="Wk 22",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk22'!$A:$I,9,0),"Check")))))
I have a macro as per below;
Quote:
Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long
fndList = Array("Wk 14", "Wk 15", "Wk 16", "Wk 17", "Wk14", "Wk15", "Wk16", "wk17")
rplcList = Array("Wk 18", "Wk 19", "Wk 20", "Wk 21", "Wk18", "Wk19", "Wk20", "wk21")
'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End Sub
the formula example is below.
Quote:
4 WEEKS =IF($J$2="Wk 18",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk18'!$A:$I,9,0),IF($J$2="Wk 19",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk19'!$A:$I,9,0),IF($J$2="Wk 20",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk20'!$A:$I,9,0),IF($J$2="Wk 21",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk21'!$A:$I,9,0),"Check"))))
Quote:
5 WEEKS =IF($J$2="Wk 18",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk18'!$A:$I,9,0),IF($J$2="Wk 19",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk19'!$A:$I,9,0),IF($J$2="Wk 20",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk20'!$A:$I,9,0),IF($J$2="Wk 21",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk21'!$A:$I,9,0),IF($J$2="Wk 22",VLOOKUP(J5,'[Oliver Adams Weekly KPI''s - 2016.xlsx]Wk22'!$A:$I,9,0),"Check")))))