PC Review


Reply
Thread Tools Rate Thread

Chart Macro Problems

 
 
R Tanner
Guest
Posts: n/a
 
      19th Jun 2008
Can anyone help me identify what I am doing wrong with this macro? I
am getting error message when I try to run it. It is telling me that
I am not completing the end if statement.


Sub createchart()
Dim cw As Long, rh As Long
Dim mp(1 To 4) As Integer

cw = Application.Sheets("Sheet4").Shape("Rounded Rectangle 2").Width
rh = Application.Sheets("Sheet4").Shape("Rounded Rectangle 2").Height
ct = Application.ActiveSheet.ChartObjects.Add(cw - 1, rh - 1, cw - 1,
rh - 5)
mp(1) = ActiveWorkbook.Sheets(1).Range("A22")
mp(2) = ActiveWorkbook.Sheets(1).Range("A23")
mp(3) = ActiveWorkbook.Sheets(1).Range("A24")
mp(4) = ActiveWorkbook.Sheets(1).Range("A25")

If ActiveWorkbook.Sheets(1).Range("A22") > 0 Then
ct.Chart.SeriesCollection.Add _
Source:=ActiveSheet.Range("C18" + Range("A22").Value), _
SeriesLabels:=True
Else
If ActiveWorkbook.Sheets(1).Range("A23") > 0 Then
ct.Chart.SeriesCollection.Add _
Source:=ActiveSheet.Range("C19" + Range("A23").Value), _
SeriesLabels:=True
Else
If ActiveWorkbook.Sheets(1).Range("A24") > 0 Then
ct.Chart.SeriesCollection.Add _
Source:=ActiveSheet.Range("C20" + Range("A24").Value), _
SeriesLabels:=True
Else
If ActiveWorkbook.Sheets(1).Range("A25") > 0 Then
ct.Chart.SeriesCollection.Add _
Source:=ActiveSheet.Range("C21" + Range("A25").Value), _
SeriesLabels:=True
End If
With ct
.Type = xlLine
.HasTitle = True
.chartitle.Text = "Volumes Trends"
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlCategory, xlSecondary) = False
.HasAxis(xlValue, xlPrimary) = False
.HasAxis(xlValue, xlSecondary) = False
End With
End Sub

 
Reply With Quote
 
 
 
 
R Tanner
Guest
Posts: n/a
 
      19th Jun 2008
On Jun 19, 1:56 pm, R Tanner <tanner.ro...@gmail.com> wrote:
> Can anyone help me identify what I am doing wrong with this macro? I
> am getting error message when I try to run it. It is telling me that
> I am not completing the end if statement.
>
> Sub createchart()
> Dim cw As Long, rh As Long
> Dim mp(1 To 4) As Integer
>
> cw = Application.Sheets("Sheet4").Shape("Rounded Rectangle 2").Width
> rh = Application.Sheets("Sheet4").Shape("Rounded Rectangle 2").Height
> ct = Application.ActiveSheet.ChartObjects.Add(cw - 1, rh - 1, cw - 1,
> rh - 5)
> mp(1) = ActiveWorkbook.Sheets(1).Range("A22")
> mp(2) = ActiveWorkbook.Sheets(1).Range("A23")
> mp(3) = ActiveWorkbook.Sheets(1).Range("A24")
> mp(4) = ActiveWorkbook.Sheets(1).Range("A25")
>
> If ActiveWorkbook.Sheets(1).Range("A22") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C18" + Range("A22").Value), _
> SeriesLabels:=True
> Else
> If ActiveWorkbook.Sheets(1).Range("A23") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C19" + Range("A23").Value), _
> SeriesLabels:=True
> Else
> If ActiveWorkbook.Sheets(1).Range("A24") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C20" + Range("A24").Value), _
> SeriesLabels:=True
> Else
> If ActiveWorkbook.Sheets(1).Range("A25") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C21" + Range("A25").Value), _
> SeriesLabels:=True
> End If
> With ct
> .Type = xlLine
> .HasTitle = True
> .chartitle.Text = "Volumes Trends"
> .HasAxis(xlCategory, xlPrimary) = True
> .HasAxis(xlCategory, xlSecondary) = False
> .HasAxis(xlValue, xlPrimary) = False
> .HasAxis(xlValue, xlSecondary) = False
> End With
> End Sub


I have a declaration at the top for ct.....

Private ct As Object
 
Reply With Quote
 
ward376
Guest
Posts: n/a
 
      19th Jun 2008
The elses and ifs should be together:

instead of:
Else
If ActiveWorkbook.Sheets(1).Range("A23") > 0 Then
try
Elseif ActiveWorkbook.Sheets(1).Range("A23") > 0 Then

Otherwise, an end if is required for each if.

Cliff Edwards
 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      20th Jun 2008
> I am getting error message when I try to run it.

Which error? What's the error number AND description? What line is
highlighted?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"R Tanner" <(E-Mail Removed)> wrote in message
news:c7b7f827-1ae5-4a6f-9420-(E-Mail Removed)...
> Can anyone help me identify what I am doing wrong with this macro? I
> am getting error message when I try to run it. It is telling me that
> I am not completing the end if statement.
>
>
> Sub createchart()
> Dim cw As Long, rh As Long
> Dim mp(1 To 4) As Integer
>
> cw = Application.Sheets("Sheet4").Shape("Rounded Rectangle 2").Width
> rh = Application.Sheets("Sheet4").Shape("Rounded Rectangle 2").Height
> ct = Application.ActiveSheet.ChartObjects.Add(cw - 1, rh - 1, cw - 1,
> rh - 5)
> mp(1) = ActiveWorkbook.Sheets(1).Range("A22")
> mp(2) = ActiveWorkbook.Sheets(1).Range("A23")
> mp(3) = ActiveWorkbook.Sheets(1).Range("A24")
> mp(4) = ActiveWorkbook.Sheets(1).Range("A25")
>
> If ActiveWorkbook.Sheets(1).Range("A22") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C18" + Range("A22").Value), _
> SeriesLabels:=True
> Else
> If ActiveWorkbook.Sheets(1).Range("A23") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C19" + Range("A23").Value), _
> SeriesLabels:=True
> Else
> If ActiveWorkbook.Sheets(1).Range("A24") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C20" + Range("A24").Value), _
> SeriesLabels:=True
> Else
> If ActiveWorkbook.Sheets(1).Range("A25") > 0 Then
> ct.Chart.SeriesCollection.Add _
> Source:=ActiveSheet.Range("C21" + Range("A25").Value), _
> SeriesLabels:=True
> End If
> With ct
> .Type = xlLine
> .HasTitle = True
> .chartitle.Text = "Volumes Trends"
> .HasAxis(xlCategory, xlPrimary) = True
> .HasAxis(xlCategory, xlSecondary) = False
> .HasAxis(xlValue, xlPrimary) = False
> .HasAxis(xlValue, xlSecondary) = False
> End With
> End Sub
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to change position of chart labels on line chart Shane Henderson Microsoft Excel Charting 1 27th May 2011 09:31 AM
Chart Macro?!! Help Please James8309 Microsoft Excel Programming 0 9th Jul 2008 02:10 AM
chart macro mohavv Microsoft Excel Misc 6 5th Jun 2008 02:31 AM
Macro and chart help millwalll Microsoft Excel Programming 8 11th Jan 2008 12:50 PM
Method of adding a chart with a chart.add in a macro ExcelNewbie Microsoft Excel Charting 1 13th Feb 2004 04:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:36 PM.