Spacing out a batch Find/Replace so that it proceeds in smaller 'chunks'

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
The server I'm pulling stock quotes from has added a request-limit of 50 quote-requests / second; if you request more than that, it disconnects you. My current code requests 500 at once, so I need to revise it so that it spaces out those requests over 10 seconds.

The way the formulas are 'activated' in the code below is by replacing the '$' at the start of the string with a '=' so that Excel converts it to a formula (which sends the quote-request). Each row (from 43 to 452) has the formulas for one stock quote. As you can see below, I currently just do a batch Find/Replace for all 500 rows (D43:S452) at once, but I need it to do it in batches of 50 (e.g. D43:S92), then pause 1.25 seconds, then do it for the next batch (D93:S142), and so on.

Code:
Sub     
    Application.ScreenUpdating = False
    With Sheets("Kitty")
        With .Range("D43:S452")
                    .Replace What:="#", Replacement:="=", LookAt:=xlPart, _
                        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                        ReplaceFormat:=False
        End With
    End With
    Application.ScreenUpdating = True
    Application.CutCopyMode = False


End Sub
 
You could use Application.OnTime to schedule a batch at 2 second intervals. As for Wait, the precision is 1 second, and if the server is anal, it may boot you if you use 1-second intervals.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You could use Application.OnTime to schedule a batch at 2 second intervals. As for Wait, the precision is 1 second, and if the server is anal, it may boot you if you use 1-second intervals.

OK...is the "Application.OnTime" function different from Wait/Loop, in that it'll avoid the problem I posted where Excel is for some reason "holding" all of the RTD messages until the entirety of the code is finished running, and then just releasing them in 1 big batch?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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