Results 1 to 2 of 2

Chart update working when macro executed step by step but not when at full execution

Threaded View

  1. #1
    Registered User
    Join Date
    07-10-2019
    Location
    Switzerland
    MS-Off Ver
    365
    Posts
    4

    Chart update working when macro executed step by step but not when at full execution

    Dear All,

    I've got a weird behavior of my macro. The data is x,y,z set of points (scan of a surface); I want to analyze the surface state, so at Y fixed I draw a plot (x,z), i get a x,y scatter plot of the section.
    I need to detrend it so i use a 6th degree interpolation. I extract the interpolation from the trendline (TrendLineValue function in VBA) of the grape since LINEST at high degree is not working properly (I know it is dirty but I already spend a lot of time on that).
    Then detrend the data, compute root mean square and store it in an array.
    And I iterate through different Y (I call them steps).
    The problem is between steps, the chart is not updated so trendline equation is not updated so value extracted by TrendLineValue are wrong....
    I played around with DoEvents, Wait, application. Calculate but nothing is working....

    Please do not mind all code related to FFT, I'm just trying to make this coefficient extraction working.
    Thank you for your help.

    Here is the file:
    gofile.io/?c=q9X9YE

    here is the code

    Sub scanPlate()
    
    Dim Step_start As Integer
    Dim Step_stop As Integer
    Dim max_peaks As New Collection
    Dim RMS As New Collection
    
    Application.ScreenUpdating = True
    'dy
    Step_start = ActiveSheet.Range("AH5").Value
    Step_stop = ActiveSheet.Range("AI5").Value
    'dx
    ActiveSheet.Range("M11").Value = ActiveSheet.Range("AH4").Value
    ActiveSheet.Range("M12").Value = ActiveSheet.Range("AI4").Value
    
    
    Range("M1").Value = Step_start
    'extract trend line coefficients of first step
    
    TrendLineValue
    Application.Calculate
    
    'iteration through differetn steps of interest
    
    Dim J As Integer
    
    For J = Step_start To Step_stop Step 2
    
            'step no
            Range("M1").Value = J
         
            'FFT_MACRO: other macro that will be implemented later
            
            'extract trend line coefficients of step J
            TrendLineValue
                   
            Debug.Print Range("M32").Value
            
            'store RMS and FTT value
            
            max_peaks.Add Range("M26").Value
            RMS.Add Range("M32").Value
            
            
            Debug.Print "step no: " & J
            
           
    Next J
    
    Debug.Print "scan finish"
    
    
    'transform collection to arrays
    
    arrPeaks = toArray(max_peaks)
    arrRMS = toArray(RMS)
    
    'display in the sheet all RMS and PEAK value
    
    Range("AA1:AA119") = Application.Transpose(arrPeaks)
    Range("AB1:AB119") = Application.Transpose(arrRMS)
    
    Range("Z1").Value = Step_start
    
    
    Application.Calculation = xlAutomatic
    
    End Sub

    Function toArray(col As Collection)
      Dim Arr() As Variant
      ReDim Arr(0 To col.Count - 1) As Variant
      
        Dim i As Integer
      For i = 1 To col.Count
          Arr(i - 1) = col(i)
      Next
      toArray = Arr
    End Function
    
    
     
    Function TrendLineValue()
    
        Dim c As Chart
        Dim t As Trendline
        Dim s As String
        Dim i As Integer
        Dim remaining As String
        Dim c0, c1, c2, c3, c4, c5, c6 As String
        Dim Arr As Variant
        ReDim Arr(0 To 7) As Variant
        
     
        
        Application.CalculateFull
        ' Get the trend line object
        ' this code assumes the first chart on the active sheet,
        '   and the first series, first trendline
        Set c = ActiveSheet.ChartObjects(2).Chart
        Set t = c.SeriesCollection(1).Trendlines(1)
    
        ' make sure equation is displayed
        t.DisplayRSquared = False
        t.DisplayEquation = True
    
        ' set number format to ensure accuracy
        '   adjust to suit requirements
        t.DataLabel.NumberFormat = "0.0000000000E+00"
    
        ' get the equation
        s = t.DataLabel.Text
    
    
        ' massage the equation string into form that will evaluate
        ' this code assumes 6rd order polynomial
        s = Replace(s, "y = ", "")
        s = Replace(s, " ", "")
        
        'extract each coefficients from string equation
        
         c6 = Left(s, InStr(1, s, "x") - 1)
        remaining = Right(s, Len(s) - InStr(1, s, "x") - 1)
        Arr(0) = c6
        
        c5 = Left(remaining, InStr(1, remaining, "x") - 1)
        remaining = Right(remaining, Len(remaining) - InStr(1, remaining, "x") - 1)
        Arr(1) = c5
        
         c4 = Left(remaining, InStr(1, remaining, "x") - 1)
        remaining = Right(remaining, Len(remaining) - InStr(1, remaining, "x") - 1)
        Arr(2) = c4
        
         c3 = Left(remaining, InStr(1, remaining, "x") - 1)
        remaining = Right(remaining, Len(remaining) - InStr(1, remaining, "x") - 1)
        Arr(3) = c3
        
         c2 = Left(remaining, InStr(1, remaining, "x") - 1)
        remaining = Right(remaining, Len(remaining) - InStr(1, remaining, "x") - 1)
        Arr(4) = c2
        
         c1 = Left(remaining, InStr(1, remaining, "x") - 1)
         remaining = Right(remaining, Len(remaining) - InStr(1, remaining, "x") - 0)
        Arr(5) = c1
        
        c0 = remaining
        Arr(6) = c0
        'display coefficeint on the sheets
        
    Dim Destination As Range
    Set Destination = ActiveSheet.Range("AU6")
    Set Destination = Destination.Resize(UBound(Arr), 1)
    Destination.Value = Application.Transpose(Arr)
    
    End Function
    Last edited by olhey; 07-11-2019 at 10:45 AM. Reason: New readings

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] macro works in step through but not in full speed mode
    By charliec in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2019, 02:14 PM
  2. Macro errors when running, but works when done step by step
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2018, 03:54 PM
  3. Replies: 2
    Last Post: 01-11-2017, 12:24 AM
  4. [SOLVED] Stock Chart apparence is different if Macro1 runs step by step not directly !
    By HerryMarkowitz in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-23-2014, 04:31 AM
  5. ~ Need Step-by-step Guide on How To Create A Chart ~
    By exceltoohard in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-06-2013, 01:04 AM
  6. [SOLVED] preventing simple zoom macro from running step by step
    By reece1984 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-11-2012, 06:13 AM
  7. [SOLVED] I need step by step instructions to create a macro for 10 imbedde.
    By diana in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-30-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1