473,386 Members | 1,673 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,386 software developers and data experts.

Help to simplify excel vba code

Hi, I am new to programming so please bear with me. I have pieced together a code which accomplished what I want it to do (creates bar graphs with a target line). Now I am just trying to simplify the code.

For example, I don't want to activate and select windows...instead I would like to just call worksheets directly. Also, I think the graph definitions can be cleaned, I just don't know how.

Would appreciate any guidance!

Expand|Select|Wrap|Line Numbers
  1. Sub LoudnessChart(Row As String)
  2. Dim LChart As ChartObject
  3. Dim Lrange As Range
  4. Dim Trange As Range
  5. Dim Lstr As String
  6. Dim Lname As String
  7.  
  8.  
  9.  Windows("Sorted OSQ HC 031910.xls").Activate
  10.     Sheets("ARLSummary").Select
  11.  
  12. Set Lrange = Range(Cells(Row, 19), Cells(Row, 23))
  13. Set Trange = Range(Cells(4, 7), Cells(Row, 7))
  14.     Lname = "=ARLSummary!R" & Row & "C3"
  15.  
  16.  Windows("Sorted OSQ HC 031910.xls").Activate
  17.     Sheets("Temp").Select
  18.  
  19. Set LChart = ActiveSheet.ChartObjects.Add _
  20.         (Left:=100, Width:=375, Top:=75, Height:=225)
  21.  
  22. 'Define Seriescollection(1)
  23.     LChart.Chart.SetSourceData Source:=Lrange
  24.     LChart.Chart.ChartType = xlColumnClustered
  25.     LChart.Chart.SeriesCollection(1).XValues = "=ARLSummary!R3C19:R4C23"
  26.  
  27.      LChart.Chart.SeriesCollection(1).Name = Lname
  28.        With LChart.Chart
  29.         .HasLegend = False
  30.         .HasTitle = True
  31.         .ChartTitle.Characters.Text = Lname
  32.         .Axes(xlCategory).HasTitle = False
  33.          .Axes(xlCategory).TickLabelSpacing = 1
  34.       '  .Axes(xlCategory).TickLabels.Orientation = xlUpward
  35.         .Axes(xlValue).HasTitle = True
  36.         .Axes(xlValue).AxisTitle.Characters.Text = "Sones"
  37.         End With
  38.  
  39. 'Define Seriescollection(2)
  40.      LChart.Chart.SeriesCollection.Add Source:=Trange
  41.         With LChart.Chart.SeriesCollection(2)
  42.             .ChartType = xlXYScatter
  43.             .XValues = "=(ARLSummary!R4C6,ARLSummary!R172C6)"
  44.             ' .values = cells(4, 7)
  45.             .Values = "=(ARLSummary!R4C7,ARLSummary!R172C7)"
  46.             .Name = "Target"
  47.             .ErrorBar Direction:=xlX, Include:=xlMinusValues, Type:=xlFixedValue, Amount:=1
  48.         End With
  49.  
  50.     With LChart.Chart.SeriesCollection(2)
  51.         .Shadow = False
  52.         .MarkerStyle = xlNone
  53.     End With
  54.  
  55.     With LChart.Chart.SeriesCollection(2).ErrorBars
  56.         .Border.LineStyle = xlContinuous
  57.         .Border.ColorIndex = 3
  58.         .Border.Weight = xlMedium
  59.         .EndStyle = xlNoCap
  60.     End With
  61.  
  62.     With LChart.Chart
  63.         .HasAxis(xlCategory, xlPrimary) = True
  64.         .HasAxis(xlCategory, xlSecondary) = True
  65.         .HasAxis(xlValue, xlPrimary) = True
  66.         .HasAxis(xlValue, xlSecondary) = False
  67.         .ApplyDataLabels AutoText:=True
  68.         .PlotArea.Interior.ColorIndex = xlNone
  69.     End With
  70.  
  71.     With LChart.Chart.Axes(xlCategory, xlSecondary)
  72.         .MinimumScale = 0
  73.         .MaximumScale = 1
  74.         .MajorTickMark = xlNone
  75.         .MinorTickMark = xlNone
  76.         .TickLabelPosition = xlNone
  77.     End With
  78.  
  79.     With LChart.Chart.SeriesCollection(1).DataLabels.Font
  80.         .Name = "Arial"
  81.         .FontStyle = "Bold"
  82.         .Size = 10
  83.         .ColorIndex = 32
  84.     End With
  85.  
  86.     With LChart.Chart.SeriesCollection(2).DataLabels.Font
  87.         .Name = "Arial"
  88.         .FontStyle = "Bold"
  89.         .Size = 10
  90.         .ColorIndex = 3
  91.     End With
  92.  End Sub
  93.  
Apr 23 '10 #1
0 1183

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

Similar topics

4
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to...
3
by: Larry Rekow | last post by:
I've built various web apps using Frontpage and/or ASP and Access, but now I'm trying to figure a way to do the following, perhaps in ASP.Net My friend gets parts lists in invoices (they are in...
3
by: CR | last post by:
To prepare a PC for my .NET apps I have to run mdac_typ.exe, dotnetfx.exe, and .NET setup programs for every application. Since I have around 8 apps this adds up to 10 installs for every pc. Is...
1
by: Coleen | last post by:
To export data from a datagrid to an excel file. I am using VB.net/ASP.net v 2003, and not connecting to an SQL database. I have an existing datagrid that I want to get the data from and download...
7
by: freeskier | last post by:
Hello, I am looking for some advice on collecting data. We are working on collecting about 20 different data points from 60 initial people, later to be expanded to approximately 200. At present we...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
5
by: runsun | last post by:
Thanks in advance. This program is written in C. It needs to read all characters from a file; then write them into a 3D array (yes, 3D!). The file is a .prn file (one of the Excel types), which...
1
AmLegacy
by: AmLegacy | last post by:
I'm having a hard time figuring out how to simplify the fractions. Can anyone look at this code and see if you can see something I don't. //This is the fraction adding function void add_fractions...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.