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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
In that case you can get rid of the loop as it isn't doing anything
VBA Code:
Sub Default_test()
   Dim Ary As Variant
  
   Ary = Array("Actual Results", "BLANK")
   With ActiveSheet.Range("A5:j550")
      .Replace Ary(0), "=" & Ary(0), xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).Offset(1, 0).Value = Ary(1)
      .Replace "=" & Ary(0), Ary(0), xlWhole, , False, , False, False
   End With
  
 MsgBox "DONE!"
End Sub
Although this won't cure your problem.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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