MSC: VBA Macro for arranging data in Excel

. Monday, August 8, 2011
  • Agregar a Technorati
  • Agregar a Del.icio.us
  • Agregar a DiggIt!
  • Agregar a Yahoo!
  • Agregar a Google
  • Agregar a Meneame
  • Agregar a Furl
  • Agregar a Reddit
  • Agregar a Magnolia
  • Agregar a Blinklist
  • Agregar a Blogmarks

Below is the macro to organize the data in the CSV files using excel.
It will remove all the chromosomes and the last lap time, then it'll insert the max and average values for all generations beside the fitness values, and then insert a line chart based on the max and average data.


Sub delete_unwanted_rows()
'
' delete_unwanted_rows Macro
'
    Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Select
    Range(ActiveCell, ActiveCell.Offset(0, 9)).Select
    Selection.Cut
    Range("A1").Select
    ActiveSheet.Paste
    Selection.End(xlDown).Select
   
    For i = 1 To 1000
        Range(ActiveCell, ActiveCell.Offset(12, 32)).Select
        Selection.ClearContents
   
        Selection.End(xlDown).Select
        Range(ActiveCell, ActiveCell.Offset(0, 9)).Select
        Selection.Cut
        Selection.End(xlUp).Select
        ActiveCell.Offset(1, 0).Select
        ActiveSheet.Paste
        Selection.End(xlDown).Select
    Next i

End Sub

Sub Data_for_chart()
'
' Data_for_chart Macro
'
    Range("L1").Select
    ActiveCell.FormulaR1C1 = "=MAX(RC[-11]:RC[-2])"
    Range("L1").Select
    Selection.Copy
    For i = 1 To 1000
        ActiveCell.Offset(1, 0).Select
        ActiveSheet.Paste
    Next i
    Application.CutCopyMode = False
   
    Range("M1").Select
    ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-12]:RC[-3])"
    Range("M1").Select
    Selection.Copy
    For i = 1 To 1000
        ActiveCell.Offset(1, 0).Select
        ActiveSheet.Paste
    Next i
    Application.CutCopyMode = False
   
    Range("L1000").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlUp)).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range(ActiveSheet.Name & "!$L$1:$M$1000")
    ActiveChart.ChartType = xlLine
    ActiveChart.SeriesCollection(1).Name = "=""Max"""
    ActiveChart.SeriesCollection(2).Name = "=""Average"""
End Sub

0 comments:

me me