-
WSarjay13
AskWoody LoungerRetiredGeek
Thanks for the code. It took me awhile to determine the best way to implement it in my macro. Once done, it works like a charm. The main problem was that I had to abandon using cell references in the addchart stament if favor of using points. Once I did that it all came together.
Thanks Again
Arjay -
WSarjay13
AskWoody LoungerSteve
Yes, I usually use linest for the bulk of my work but I occasionally find it more convenient to just grab the regression equation from the chart for a quick check.
Arjay -
WSarjay13
AskWoody LoungerRetiredgeek
Thanks for the additional suggestion. A nice elegant addition.
Arjay -
WSarjay13
AskWoody LoungerSdckapr
Many thanks for the prompt reply as well as the tidy code. It works better and cleaner than what I had ginned up. I discovered that if I copy the entire trendline equation including the “=” (accounting for the added characters in the “left” and “mid” commands), the macro doesn’t get the exponents and leading signs correct with a leading minus sign after the “=”. If I leave out the “=” sign and carefully cut the equation, it works perfectly!
Thanks
Arjay -
WSarjay13
AskWoody LoungerI ended up having to Dim the variables as variant. i also forced the trendline through the origin. It works quite nicely. Thank you so much!
Sub chart()
‘
Dim cubiccoeff As Variant
Dim quadcoeff As Variant
Dim linearcoeff As Variant‘name data ranges
Range(“F5”).Activate
Range(ActiveCell, Selection.End(xlDown)).Select
Selection.Name = “yPDCBData”
Range(“E5”).Activate
Range(ActiveCell, Selection.End(xlDown)).Select
Selection.Name = “xPDCBData”
Range(ActiveCell, ActiveCell.Offset(0, 1)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Name = “PDCBData”‘calculate and print cubic regression coefficients
cubiccoeff = Evaluate(“=INDEX(LINEST(yPDCBData,xPDCBData^{1,2,3 },0,1),1)”)
quadcoeff = Evaluate(“=INDEX(LINEST(yPDCBData,xPDCBData^{1,2,3 },0,1),1,2)”)
linearcoeff = Evaluate(“=INDEX(LINEST(yPDCBData,xPDCBData^{1,2,3 },0,1),1,3)”)Range(“AD32”).Value = “Trendline Coefficients”
Range(“AA34”).Value = “X^3”
Range(“AA35”).Value = “X^2”
Range(“AA36”).Value = “X”Range(“AB33”).Value = “PDCB”
Range(“AB34”).Value = cubiccoeff
Range(“AB35”).Value = quadcoeff
Range(“AB36”).Value = linearcoeff -
WSarjay13
AskWoody Loungersdckapr
Interesting approach. As a newbie, I am still somewhat less than fluent in VBA. I understand what you did with the named ranges. It also occured to me as I was driving home that I may have Dim_ed vCubiccoeff incorrectly as well as having a “:” in the linest equation. I’ll give it a shot tomorrow morning when I get to work. But why use “Evaluate” instead of just “=” ?
Arjay13 -
WSarjay13
AskWoody LoungerWow! I knew it was something goofy but had no clue as to what the issue was. I see that there is a listing of “Thanks”. How about Thank you, Thank you, Thank you! Three times in one post. I started programming back in the punch card days (and then stopped for 25 years) and I just knew that it something weird like that. I don’t get to SC very often (I was in Aiken two years back at the Savannah River Lab)but I do owe you a cold one! Have a great weekend.
-
WSarjay13
AskWoody Lounger27985-GC2-R10-NA6-Standards-Mar-25-2011
RG
Interestingly, when I started with a new spreadsheet and manually entered the headers, the macro worked like a charm. However, it doesnt work on my data files for no discernible reason to me. Other macros have worked just fine so I am stumped. Have a look and see what you think. Thanks! -
WSarjay13
AskWoody LoungerThanks sdckapr! That works perfectly. I am new to VBA and don’t have an extensive knowledge of the syntax yet. I never would have come up with that solution. I will study it so I can get a little bit better. Thanks Again!
Arjay -
WSarjay13
AskWoody LoungerI’d like the macro to continue as if nothing happened. In other words, if I click on “no” or “cancel” I don’t want the code to do anything- just proceed as if nothing happened.
-
WSarjay13
AskWoody LoungerThis is a portion of my macro. The runtime error is generated on the last line when there is an existing file with the same name I am using to save the current workbook.
Private Sub Ok_Click()
Dim Workrange As Range
Dim Oldsheet As String
Dim newsheet As String
Dim oldworkbook As String
Dim Saveworkbook As String‘macro to save CSV as an xls & add a sheet & return to the original sheet
oldworkbook = ActiveWorkbook.Name
‘replace csv with xls as file extension
Saveworkbook = Replace(oldworkbook, “csv”, “xls”)
‘save file as xls
ActiveWorkbook.SaveAs Filename:=Saveworkbook, FileFormat:=xlExcel8 -
WSarjay13
AskWoody LoungerSorry – I get:
Run-time error ‘1004’:
Method ‘Save as’ of ‘object_workbook’ failed -
WSarjay13
AskWoody LoungerApril 15, 2011 at 10:12 pm in reply to: Copy certain rows of data to new spreadsheet problem #1276149geof
The only reason stopping me is I am learning a new programming language – so i start with simple steps. In this case, S and s would signify the same thing to me, so they actually sould be in the same range or region. I will try again on Monday. Thank you for your insight. Btw, I was in Aukland 10 years ago. Wonderful place. Got down to Rota Rua to the geothermal springs. Didn’t get down to south island though. Have a college buddy down in Christchurch. He luckily missed the earthquake by a couple of miles. thanks for your input and be well.
Arjay13 -
WSarjay13
AskWoody LoungerApril 15, 2011 at 10:06 pm in reply to: Copy certain rows of data to new spreadsheet problem #1276148sdckapr
as a newbie to VBA programming, I did not fully appreciate all the nuances of the code. I just started reading books last week. Thank you! -
WSarjay13
AskWoody LoungerAh Yes. In the back of my tiny mind, I was thinking about an Else…nicely done
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Perplexity CEO says its browser will track everything users do online
by
Alex5723
7 hours, 4 minutes ago -
Login issues with Windows Hello
by
CWBillow
7 hours, 50 minutes ago -
How to get into a manual setup screen in 2024 Outlook classic?
by
Tex265
10 hours, 3 minutes ago -
Linux : ARMO rootkit “Curing”
by
Alex5723
19 hours, 22 minutes ago -
Employee monitoring app leaks 21 million screenshots in real time
by
Alex5723
19 hours, 28 minutes ago -
Google AI is now hallucinating idioms
by
Alex5723
20 hours ago -
april update
by
69800
15 hours, 58 minutes ago -
Windows 11 Insider Preview build 27842 released to Canary
by
joep517
20 hours, 54 minutes ago -
Quick Fix for Slowing File Explorer
by
Drcard:))
21 hours, 6 minutes ago -
WuMgr not loading?
by
LHiggins
21 hours, 42 minutes ago -
Word crashes when accessing Help
by
CWBillow
1 hour, 12 minutes ago -
New Microsoft Nag — Danger! Danger! sign-in to your Microsoft Account
by
EricB
20 hours, 45 minutes ago -
Blank Inetpub folder
by
Susan Bradley
18 hours, 9 minutes ago -
Google : Extended Repair Program for Pixel 7a
by
Alex5723
1 day, 7 hours ago -
Updates seem to have broken Microsoft Edge
by
rebop2020
17 hours, 42 minutes ago -
Wait command?
by
CWBillow
1 day ago -
Malwarebytes 5 Free version manual platform updates
by
Bob99
1 day, 13 hours ago -
inetpub : Microsoft’s patch for CVE-2025–21204 introduces vulnerability
by
Alex5723
1 day, 20 hours ago -
Windows 10 finally gets fix
by
Susan Bradley
2 days, 5 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.04.09.545
by
Alex5723
2 days, 6 hours ago -
How to use Skype after May?
by
Joann
15 hours, 4 minutes ago -
Win 7 MS Essentials suddenly not showing number of items scanned.
by
Oldtimer
2 days, 1 hour ago -
France : A law requiring messaging apps to implement a backdoor ..
by
Alex5723
2 days, 19 hours ago -
Dev runs Windows 11 ARM on an iPad Air M2
by
Alex5723
2 days, 20 hours ago -
MS-DEFCON 3: Cleanup time
by
Susan Bradley
45 minutes ago -
KB5056686 (.NET v8.0.15) Delivered Twice in April 2025
by
lmacri
1 day, 1 hour ago -
How to enable Extended Security Maintenance on Ubuntu 20.04 LTS before it dies
by
Alex5723
3 days, 7 hours ago -
Windows 11 Insider Preview build 26200.5562 released to DEV
by
joep517
3 days, 11 hours ago -
Windows 11 Insider Preview build 26120.3872 (24H2) released to BETA
by
joep517
3 days, 11 hours ago -
Unable to eject external hard drives
by
Robertos42
1 day, 22 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.