SendKeys "{ESC}" Not working on Code

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
765
Hello friends, Hope all is well!

Strange thing, the below code works but Very slow. When I press the Esc button the code runs fast & smooth.
Please help me apply the Esc command within the code please.

Thank you So much in advance!

Code:
Sub B_REV()
Dim aSeries As Series

Application.ScreenUpdating = True
ActiveSheet.ChartObjects("Chart 9").Select
    
    For Each aSeries In ActiveChart.SeriesCollection
        Select Case UCase(aSeries.Name)
        Case "REV"
        Case Else
            aSeries.Delete
            End Select
        Next aSeries
          
    num_rows = Sheet6.Range("A1").CurrentRegion.Rows.Count - 1
        ActiveChart.SeriesCollection.NewSeries
                ActiveChart.SeriesCollection(2).XValues = Sheets("REV").Cells(2, 1)
                ActiveChart.SeriesCollection(2).Values = Sheets("REV").Cells(2, 2)

 For r = 2 To num_rows
      
    Sheets("REV").Cells(r, 4) = Sheets("REV").Cells(r, 1)
    Sheets("REV").Cells(r, 5) = Sheets("REV").Cells(r, 2)
    ActiveChart.SeriesCollection(2).XValues = Sheets("REV").Cells(r, 4)
    ActiveChart.SeriesCollection(2).Values = Sheets("REV").Cells(r, 5)

            If Sheets("chart").Range("AJ1") = "True" Then
                      
           Application.Wait Now()
                                 
        End If
    Next r

        ActiveChart.SeriesCollection(2).Delete
End Sub
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Unless there is a very specific reason for the opposite I suggest you start by removing these three lines from your code.
Code:
            If Sheets("chart").Range("AJ1") = "True" Then
           Application.Wait Now()
        End If
SendKeys better be avoided unless absolutely necessary.
its behavior is not exactly unpredictable, but it needs complete control over the environment to be certain of the outcome.
 
Last edited:
Upvote 0
What pressing ESC could be doing is cancelling calculation which is probably why doing so speeds things up.

Have you tried setting calculation to manual at the start of the code and setting it back to automatic at the end?

That would kind of be like the equivalent of hitting ESC.
 
Upvote 0
Great & thank you! Can you please help me, where is it best to place the lines below in the code (which lines of the code)?

Application.Calculation = xlManual

Application.Calculation = xlAutomatic
 
Upvote 0
Set calculation to manual at the same spot you set turn screen updating off and set it back to automatic before End Sub.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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