roc_on_the_rocks
Board Regular
- Joined
- Jun 6, 2009
- Messages
- 175
- Office Version
- 365
- Platform
- Windows
Let's say I receive spreadsheets from a Dairy Farm, with over one hundred of cows, but I'm currently tracking milk productions of about six cows (Daisy, Kammi, Lina, Lulu, Madeleine and Shakira). I plot their daily milk production on graphs and do some further data manipulation with them.
I have recorded a macro to automate this tedious and time-consuming task... but the problem is that the cow names - and their data - come in different columns each time I receive a report, requiring me to manually organize the columns in the way they were recorded, which almost defeats the purpose of my macro.
I believe this is a recurring question but I couldn't find anything that I could apply (I did try tweaking few ones, w/o luck). This is Excel 2003.
Could any good soul please shed some light for me? Many thanks in advance.
PS.: Cow names come in different columns in row 31. Daily milk production comes in rows 34 and down, but it varies from report to report, so it would be great if this macro could identify the last row in each report I receive.
Here's what I use today:
Sub Graph_Milk()
'
' Graph_Test Macro
' Macro recorded 3/27/2009 by Ricardo
'
'
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Screen 2_06-09-2009_04-49-59-PM"). _
Range("E4")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(1).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C9:R1695C9"
ActiveChart.SeriesCollection(1).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C9"
ActiveChart.SeriesCollection(2).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(2).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C14:R1695C14"
ActiveChart.SeriesCollection(2).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C13"
ActiveChart.SeriesCollection(3).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(3).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C31:R1695C31"
ActiveChart.SeriesCollection(3).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C31"
ActiveChart.SeriesCollection(4).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(4).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C31:R1695C31"
ActiveChart.SeriesCollection(4).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C33"
ActiveChart.SeriesCollection(5).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(5).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C36:R1695C36"
ActiveChart.SeriesCollection(5).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C36"
ActiveChart.SeriesCollection(6).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(6).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C39:R1695C39"
ActiveChart.SeriesCollection(6).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C39"
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub
I have recorded a macro to automate this tedious and time-consuming task... but the problem is that the cow names - and their data - come in different columns each time I receive a report, requiring me to manually organize the columns in the way they were recorded, which almost defeats the purpose of my macro.
I believe this is a recurring question but I couldn't find anything that I could apply (I did try tweaking few ones, w/o luck). This is Excel 2003.
Could any good soul please shed some light for me? Many thanks in advance.
PS.: Cow names come in different columns in row 31. Daily milk production comes in rows 34 and down, but it varies from report to report, so it would be great if this macro could identify the last row in each report I receive.
Here's what I use today:
Sub Graph_Milk()
'
' Graph_Test Macro
' Macro recorded 3/27/2009 by Ricardo
'
'
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Screen 2_06-09-2009_04-49-59-PM"). _
Range("E4")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(1).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C9:R1695C9"
ActiveChart.SeriesCollection(1).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C9"
ActiveChart.SeriesCollection(2).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(2).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C14:R1695C14"
ActiveChart.SeriesCollection(2).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C13"
ActiveChart.SeriesCollection(3).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(3).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C31:R1695C31"
ActiveChart.SeriesCollection(3).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C31"
ActiveChart.SeriesCollection(4).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(4).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C31:R1695C31"
ActiveChart.SeriesCollection(4).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C33"
ActiveChart.SeriesCollection(5).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(5).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C36:R1695C36"
ActiveChart.SeriesCollection(5).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C36"
ActiveChart.SeriesCollection(6).XValues = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C1:R2000C1"
ActiveChart.SeriesCollection(6).Values = _
"='Screen 2_06-09-2009_04-49-59-PM'!R34C39:R1695C39"
ActiveChart.SeriesCollection(6).Name = _
"='Screen 2_06-09-2009_04-49-59-PM'!R31C39"
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub