basskitcase
New Member
- Joined
- May 16, 2011
- Messages
- 4
I have about 10 excel programs that all use the same macro to pull the trendline equation from a graph on one sheet and paste it to another cell on that same sheet. I created these programs in Excel 2003 but now that i have updated to 2007, something strange is happening (i am running the 2003 files in compatability mode as recreating the workbook is not feasable). When i call the macro (Macro3) it pulls the trendline equation and pastes it into a cell. I then have formulas in the adjacent cell that parse the equation into its coefficients. The next line of code after calling Macro3 pulls the coefficient and pastes it to another cell. So the flow should be:
Macro3 is called and pastes trendline to cell=>cell formulas parse and update values => next line of code excutes to copy coeffienct and paste elsewhere.
What is happening is that the next line of code after Macro3 seems to execute before Macro3 has finished pasting the trendline (or before the worksheet has properly updated, its happening to fast to tell), so the coefficients that get copied are the previous loop's coefficients. I have a workaround by calling Macro3, using an application.wait function, the calling macro3 again, but this is poor practice in my opinion and should not be required.
What is happening with 2007? why would it not ensure all code is executed and the cells have properly updated before executing the next line of code? The Macro3 code is posted below. I got this code from this site, although i don't remember who the original author was but much thanks to whomever posted it originally!!!
Sub Macro3()
Dim objTL As Trendline
Dim strText As String
With Sheet4.ChartObjects(1).Chart
Set objTL = .SeriesCollection(1).Trendlines(1)
With objTL
strText = .DataLabel.Text
End With
End With
Sheet4.Cells(7, 7) = strText
End Sub
Macro3 is called and pastes trendline to cell=>cell formulas parse and update values => next line of code excutes to copy coeffienct and paste elsewhere.
What is happening is that the next line of code after Macro3 seems to execute before Macro3 has finished pasting the trendline (or before the worksheet has properly updated, its happening to fast to tell), so the coefficients that get copied are the previous loop's coefficients. I have a workaround by calling Macro3, using an application.wait function, the calling macro3 again, but this is poor practice in my opinion and should not be required.
What is happening with 2007? why would it not ensure all code is executed and the cells have properly updated before executing the next line of code? The Macro3 code is posted below. I got this code from this site, although i don't remember who the original author was but much thanks to whomever posted it originally!!!
Sub Macro3()
Dim objTL As Trendline
Dim strText As String
With Sheet4.ChartObjects(1).Chart
Set objTL = .SeriesCollection(1).Trendlines(1)
With objTL
strText = .DataLabel.Text
End With
End With
Sheet4.Cells(7, 7) = strText
End Sub