MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 11th, 2002, 10:53 AM   #1
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

Hello this is one of my final problems and I need help with it ASAP infact the first person to solve it gets a chocolate medallion

Ok I Have A Macro assigned to a button that makes a chart all works well however I want the chart to be made onto the same worksheet all the time (which is called "Chart") but when I run it again I have a debug error and the chart is made onto another worksheet called worksheet2 (the next time it goes worksheet 3 etc.)
What I want is for each time that button is pressed the chart goes onto the chart worksheet but overwrites the other chart please help me here is the VB code

Sub MakeChart()
'
' MakeChart Macro
' Makes A Chart From The Data
'

'
Range("A2:A11,M2:M11").Select
Range("M2").Activate
Charts.Add
ActiveChart.ChartType = xlLineStacked
ActiveChart.SetSourceData Source:=Sheets("Database").Range("A2:A11,M2:M11"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Revenue"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Sales"
End With
End Sub
Morrissey is offline   Reply With Quote
Old Apr 11th, 2002, 11:05 AM   #2
lantiger
New Member
 
Join Date: Apr 2002
Posts: 24
Default

Using chart.add will always add a new chart. If you know the name of the chart, as you has suggested, you can always delete the old chart and draw the new chart.

Example:

dim cht as chart
on error resume next
set cht = ActiveWorkbook.Chart.add("YourChartNameHere")
on error goto 0

if err = 0 then
cht.delete 'This delete the old chart
end if



Your normal code here...
lantiger is offline   Reply With Quote
Old Apr 11th, 2002, 11:06 AM   #3
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

where exactly do I put this in my code then the chocolate medallion is yours!
Morrissey is offline   Reply With Quote
Old Apr 11th, 2002, 11:20 AM   #4
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

i need this
Morrissey is offline   Reply With Quote
Old Apr 11th, 2002, 11:35 AM   #5
lantiger
New Member
 
Join Date: Apr 2002
Posts: 24
Default

Hey Morrissey:
Sorry I was not clear.
Just in the same sub you have, right before your chart.add function. all it does is check if the chart already exist or not, if it does, it just delete it, so you can add the new one .
if you need more help, just lmk.

HTH
lantiger
lantiger is offline   Reply With Quote
Old Apr 11th, 2002, 11:50 AM   #6
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

One More Problem but we are nearly there I have inserted the code but another debug message comes up saying

Object variable with block not set' and the following code is highlighted

cht.Delete 'This delete the old chart

here is all the code

Sub MakeChart()
'
' MakeChart Macro
' Makes A Chart From The Data
'

'
Range("A2:A11,M2:M11").Select
Range("M2").Activate
Dim cht As Chart
On Error Resume Next
Set cht = ActiveWorkbook.Chart.Add("YourChartNameHere")
On Error GoTo 0

If Err = 0 Then
cht.Delete
End If
Charts.Add
ActiveChart.ChartType = xlLineStacked
ActiveChart.SetSourceData Source:=Sheets("Database").Range("A2:A11,M2:M11"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Revenue"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Sales"
End With
End Sub

HELP NEEDED QUICK!!!!
Morrissey is offline   Reply With Quote
Old Apr 11th, 2002, 12:05 PM   #7
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

please!!!
Morrissey is offline   Reply With Quote
Old Apr 11th, 2002, 12:15 PM   #8
Steve Hartman
Board Regular
 
Steve Hartman's Avatar
 
Join Date: Feb 2002
Location: Houston,Texas
Posts: 418
Default

How many "one last problem" does this make for you in the last six weeks now?

This is the problem with giving a man a fish instead of teaching him how to fish.

Of course the man must want to learn instead of wanting someone else do his work for him.

Goodbye Arash.

[ This Message was edited by: Steve Hartman on 2002-04-11 11:16 ]
Steve Hartman is offline   Reply With Quote
Old Apr 11th, 2002, 12:21 PM   #9
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

I'm not here for a debate on whether I should learn VBA (not a requirement of the course)or not I wish to know this problem ok this board is for helping people not getting into an ethical debate if you can't help or don't want to help no one asked ok mind your own business!
Morrissey is offline   Reply With Quote
Old Apr 11th, 2002, 12:26 PM   #10
Morrissey
Board Regular
 
Join Date: Mar 2002
Posts: 85
Default

Also I don't just insert this code and leave it alone and and take the credit for it actually to try and learn the code however I can't in 6 weeks and teach a man to fish? yes well who will teach me how MANY TIMES DO I HAVE TO SAY THIS MY TEACHER DOES NOT KNOW VBA!!!!<------- If ther is a way I could learn VBA in 6 weeks and do everything else then I would but I can't so mind your own business!
Morrissey is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:08 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes