Loop with an unintentional offset

cacahuatitaCH

New Member
Joined
Jan 8, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
So, I found this looping code and adapted it a bit, pretty superficial changes.

It works well for the first instance, finds the text I asked it to, changes the next row... but after that, it keeps changing the text in the cell it finds the actual text its supposed to be looking for as a reference.

Could you help me find the mistake?


VBA Code:
Sub Default_test()
   Dim Ary As Variant
   Dim i As Long
  
   Ary = Array("Actual Results", "BLANK")
   With ActiveSheet.Range("A5:F550")
      For i = 0 To UBound(Ary) Step 2
         .Replace Ary(i), "=" & Ary(i), xlWhole, , False, , False, False
         .SpecialCells(xlFormulas, xlErrors).Offset(1, 0).Value = Ary(i + 1)
         .Replace "=" & Ary(i), Ary(i), xlWhole, , False, , False, False
      Next i
   End With
  
 MsgBox "DONE!"
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
What do you mean it works the first time, but not after that? You are only looking to change one value
 
Upvote 0
What do you mean it works the first time, but not after that? You are only looking to change one value
The fist instance, it works as it should, but once it starts looking for the second, third and so on, it changes the cell value where it finds the text "Actual Result"
 
Upvote 0
Can you ever have two adjacent cells with Actual Result?

Also the code doesn't look a 2nd 3rd time, it does it all at once.
 
Upvote 0
Can you ever have two adjacent cells with Actual Result?

Also the code doesn't look a 2nd 3rd time, it does it all at once.
No, there´s no adjacent cell repetition.

The thing is, that it works properly on the first instance only, after that it substitutes the "Actual Result" text
 
Upvote 0
Works quite happily for me
+Fluff v2.xlsm
ABCDE
5CumbriaEdenUllswaterPenrith and The BorderMatterdale
6ShropshireShropshireCleobury MortimerLudlowFarlow
7DevonTorridgeWaldonTorridge and West DevonMilton Damerel
8Actual ResultsStockportActual ResultsHazel Grove
9BLANKCounty DurhamBLANKNorth DurhamStanley
10StaffordshireStoke-on-TrentBirches Head and Central Forest ParkStoke-on-Trent Central
11BuckinghamshireActual ResultsHambleden ValleyWycombeHambleden
12LancashireBLANKBoulsworthPendleColne
13North YorkshireHambletonOsFatherley & SwainbyActual ResultsOsFatherley
14West MidlandsBirminghamLongbridgeBLANK
15West YorkshireKirkleesKirkburtonDewsburyActual Results
16CornwallCornwallSt Teath and St BrewardNorth CornwallBLANK
17West YorkshireKirkleesColne ValleyColne Valley
18Actual ResultsPendleActual ResultsPendleActual Results
19BLANKBradfordBLANKBradford SouthBLANK
20CumbriaEdenCrosby RavensworthPenrith and The BorderCrosby Ravensworth
21DerbyshireAmber ValleyAlportDerbyshire DalesDethick, Lea and Holloway
Data


Do you have any merged cells?
 
Upvote 0
both the cells containing "Actual Results" and the ones to write "blank" into are merged, only horizontally, they do not over more than one row
 
Upvote 0
In that case it should not be a problem with this code.
Do any of the cells have formulae?
 
Upvote 0
In that case it should not be a problem with this code.
Do any of the cells have formulae?
Some of the cells to be changed to "blank" do have formulas... with no reference to the phrase"actual results".
 
Upvote 0
In that case I don't know, do you have any other values in the array to replace, or just Actual results?
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top