473,287 Members | 3,181 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Excel Vba Help Required

Hello,

Wondered if you could help me with a little issue I'm having. I'm exporting some data from Access to Excel and converting into some fancy graphs. The number of series' ranges from 2 to 5. Below isa copy of the code I am using to format the graph in terms of series names, layout, colours of lines, etc. When the full 5 series are there to be charted there is no problem with the code, however, when I try to convert less the 5 series I get an error message saying error code 400. I have tried to trap the error and it seems to be when I try to name the values on the X-axis. I've tried to take that line out but I can't seem to get it to work. Any help would be greatly appreciated.

Sub AutoExec()
Dim budgetusage As Boolean, actualcost As Boolean, budgetcost As Boolean
Dim row As Integer, series As Integer
Dim sheet_name As String, i As Integer

'MsgBox "auto"
On Error GoTo last_sheet
While 1
ActiveSheet.Next.Select
Wend
last_sheet:
sheet_name = ActiveSheet.Name
On Error GoTo 0

Sheets(sheet_name).Select
Range("A1").Select
Selection.End(xlDown).Select
row = ActiveCell.row

Cells(row + 1, 4).Formula = "=SUM(D2:D" & row & ")"
budgetusage = (Cells(row + 1, 4).Value <> 0)

Cells(row + 1, 5).Formula = "=SUM(E2:E" & row & ")"
actualcost = (Cells(row + 1, 5).Value <> 0)

Cells(row + 1, 6).Formula = "=SUM(F2:F" & row & ")"
budgetcost = (Cells(row + 1, 6).Value <> 0)

Sheets("GraphicalAnalysisWeek").Select
ActiveChart.ChartArea.Select
Sheets("GraphicalAnalysisWeek").Copy after:=Sheets(sheet_name)
Sheets(ActiveSheet.Name).Name = sheet_name & " chart"

series = 1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(series).Values = "='" & sheet_name & "'!R2C2:R" & row & "C2"
ActiveChart.SeriesCollection(series).Name = "=""Production Volume"""

series = 2
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(series).Values = "='" & sheet_name & "'!R2C3:R" & row & "C3"
ActiveChart.SeriesCollection(series).Name = "=""Usage Volume"""

series = 3

If budgetusage Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(series).Values = "='" & sheet_name & "'!R2C4:R" & row & "C4"
ActiveChart.SeriesCollection(series).Name = "=""Budget Usage"""
series = series + 1
End If

If actualcost Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(series).Values = "='" & sheet_name & "'!R2C5:R" & row & "C5"
ActiveChart.SeriesCollection(series).Name = "=""Actual Cost"""
series = series + 1
End If

If budgetcost Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(series).Values = "='" & sheet_name & "'!R2C6:R" & row & "C6"
ActiveChart.SeriesCollection(series).Name = "=""Budget Cost"""
End If
MsgBox ""

For i = 1 To series
ActiveChart.SeriesCollection(i).XValues = "='" & sheet_name & "'!R2C1:R" & row & "C1"
Next i

MsgBox ""

ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Lines on 2 Axes"
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = xlUpward
End With

ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
Selection.Font.Bold = True
With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
Selection.Shadow = False
Selection.Fill.TwoColorGradient Style:=msoGradientHorizontal, Variant:=1
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 35
.Fill.BackColor.SchemeColor = 2
End With
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlMedium
.LineStyle = xlContinuous
End With
Selection.Interior.ColorIndex = xlNone
With Selection.Border
.ColorIndex = 16
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Utilities Tracker"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Date"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Volume"
.Axes(xlCategory, xlSecondary).HasTitle = True
.Axes(xlCategory, xlSecondary).AxisTitle.Characters.Text = "£"
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
ActiveChart.ChartArea.Select
With ActiveChart
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "£"
End With
ActiveChart.SeriesCollection(5).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 41
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlAutomatic
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlAutomatic
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlAutomatic
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.SeriesCollection(5).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.SeriesCollection(3).Select
With Selection.Border
.ColorIndex = 4
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.Axes(xlValue, xlSecondary).Select
With ActiveChart.Axes(xlValue, xlSecondary)
.MinimumScaleIsAuto = True
.MaximumScale = 6000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With

End Sub
Jul 18 '06 #1
0 19558

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: zxo102 | last post by:
Hi there, I need your help for python <--> excel. I want to paste selected cells (range) to different location on the same sheet in Excel through python. I have tried it for a while but could not...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
3
by: Rik Moed | last post by:
Hi, I am having a problem with Excel 2003 worksheets when I upload them using the HtmlIputFile. After the upload, I start to download the worksheet and it appears to be currupt. I recieve the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
1
by: RickH | last post by:
..Cells(1,y).GetType ownly shows instead of .Value, .Copy, etc. The code below is derived from samples, it should work, but I've messed up somewhere... Imports System.Windows.Forms Imports...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
1
by: Anonieko | last post by:
Here are some of the approaches. 1. Transform DataGrid http://www.dotnetjohn.com/articles.aspx?articleid=36 3. Use the Export approach ...
1
by: anon1m0us | last post by:
Hi; I am waaayyy new at ASP so I am hopping someone can help me. I wrote an ASP that accepts input from a user. I need the input saved in different cells in an excel sheet. Everytime someone hits...
0
by: Wernerh | last post by:
Hi guys, Things are going great with my application. The program works like acharm thanks to Killer42 and the likes. Thanks guys. So on to the next problem :->> I have written the code to write...
5
ADezii
by: ADezii | last post by:
Periodically, the same or similar question appears in our Access Forum: How can I use Excel Functions within Access? For this reason, I decided to make this Subject TheScripts Tip of the Week. In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.