The VBA code below, you wrote for me and it works perfectly. Initially, there was an…
- User
The VBA code below, you wrote for me and it works perfectly. Initially, there was an issue with stopping the loop, but you fixed it with the code below. Now that I can stop the loop whenever I want, can you please make an alteration to it. The loop starts from M1 and runs down to the first empty cell, then it loops up and stops when it gets to M1. Can you change it so that when it gets to back to M1, it restarts the downward loop again. It will obviously continue this up and down scroll indefinately, but now I can stop it with the StopAutoScroll() event which is called from '' Skip the autoscroll stop if selecting in column M If Target.Worksheet.Name = "All Checks" And Target.Column <> 13 Then ' 13 is the column number for M StopAutoScroll End If ' in my 'Worksheet_SelectionChange' event.
Sub StartAutoScroll() Dim ws As Worksheet Dim currentCell As Range Dim lastRow As Long
' Reference the "All Checks" worksheet Set ws = ThisWorkbook.Sheets("All Checks") 'Application.EnableEvents = False ' Initialize isRunning = True lastRow = ws.Cells(ws.Rows.count, "M").End(xlUp).Row Set currentCell = ws.Range("M1") ' Start from M1 ' Loop: Scroll down the column until an empty cell is found Do While isRunning ' Stop if we have reached the last row or an empty cell If IsEmpty(currentCell) Or currentCell.Row > lastRow Then Exit Do End If ' Select the current cell currentCell.Select ' Wait (without freezing the application) Dim startTime As Double startTime = Timer Do While Timer < startTime + 0.5 ' 500 milliseconds DoEvents ' Allow other events to be processed Loop ' Move to the next cell down Set currentCell = currentCell.Offset(1, 0) ' Move down Loop ' Move upwards when reaching an empty cell If isRunning Then Do While isRunning And currentCell.Row > 1 ' Select the current cell currentCell.Select ' Wait (without freezing the application) startTime = Timer Do While Timer < startTime + 0.5 ' 500 milliseconds DoEvents ' Allow other events to be processed Loop ' Move up Set currentCell = currentCell.Offset(-1, 0) ' Move up Loop End If 'Application.EnableEvents = TrueEnd Sub
Sub StopAutoScroll() isRunning = False 'Application.EnableEvents = True End Sub
- Assistant
- User
Thanks again! Your changes worked
- Assistant
You're welcome! I'm glad to hear that the changes worked for you. If you have any more questions or need further assistance with VBA or anything else, feel free to ask. Happy coding!