Need to page down in a MS Excel VBA module once I get to approximately row 46

upobDaPlaya
upobDaPlaya used Ask the Experts™
on
I have a VBA modules that loops that thru each row in an Excel 2007 spreadsheet.  I make the spreadsheet visible to the user as it loops thru each row.  My dilemma is that once it gets to row 46 approximately the module continues to loop as expected, but visually the focus remains on row 46 and the user can not see the updates as they occur beyond row 46.

What is the code required so that the focus is in synch with the loop.  Thus if the loop is on row 56 the user should be viewing row 56.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This code loops through rows 1 to 1000, setting the active (visible) cell to column [A] of the sequential row...

Public Sub Q_28701027()

  Dim lngRow                                            As Long
  
  For lngRow = 1& To 1000&
  
      DoEvents
      
      Application.Goto Reference:=Cells(lngRow, 1), Scroll:=True
      
  Next lngRow
  
End Sub

Open in new window

Michael FowlerSolutions Consultant
Commented:
Use something like this. Just replace the Range("A100") with the values in your counter

Application.Goto Range("A100"), True 

Open in new window

Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
If fanpages' code doesn't do what you want then please attach your workbook or a facsimile.
Alternatively, if you wish the worksheet to scroll every 46 rows processed...

Public Sub Q_28701027()

  Dim lngRow                                            As Long
  
  For lngRow = 1& To 1000&
  
      DoEvents
      
      If lngRow Mod 46& = 0 Then
         Application.Goto Reference:=Cells(lngRow, 1), Scroll:=True
      End If
      
      Cells(lngRow, 1) = lngRow * Rnd() <- Setting value of column [A] on each row for a demonstration
      
  Next lngRow
  
End Sub

Open in new window

Author

Commented:
Thx..Fanpage solution worked...Michael than you for the suggestion..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial