Loop stopped working: Selection.End(xlDown).Select

kdorian

New Member
Joined
Aug 6, 2010
Messages
12
I have a loop in a macro that seems to have stopped working. This part of the macro, and the data I'm using to test the macro, have not changed since the last time I tested it, 2-3 weeks ago. All changes made to the macro take place after this part is complete. (I was trying to check something that comes later in the code.)

I have no idea what happened. I am on a different computer, but on the same network, using the same version of Windows and Excel. I have double checked the data, and the value searched for matches perfectly, including the trailing space.

Can someone explain why the code might not work and/or suggest an alternate loop that is more reliable?

Code:
Sub JLI()
 
'   Move to cell A5, check if text="Remit To: ". If so insert line before every "Remit To: " in the sheet
    Range("A5").Select
    If Range("A5").Value = "Remit To: " Then
        Selection.End(xlDown).Select
        Do Until ActiveCell.Row = 1
          If ActiveCell.Value = "Remit To: " Then
            ActiveCell.EntireRow.Insert shift:=xlDown 'Insert blank row.
            ActiveCell.Value = "blank"
          End If
            ActiveCell.Offset(-1, 0).Select 'Move up one row.
        Loop
   End If
 
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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