This may be trivial to some of you but, here goes...
I have a worksheet which comprises of a sheet of a lot of raw data from which I am trying to automate the creation of some charts. However, the amount of rows and columns can vary so here is my dilemma.
The charts always use the A column as the X-Axis but, the Y-Axis comprises of two adjacent columns which move along from chart to chart...e.g. B & C for the first one, D & E for the next and so on. I was thinking of writing a while loop searching for an empty column as it moves along (thus indicating the end) however, it is this moving along the columns which is causing the headache. The code I have so far is a little basic but, here is a cut and paste:
============================================
Sub Chart()
Dim ChartNo As Byte
Dim FullCellRef As String
Dim CellRef As String
Dim SheetName As String
Dim Fruni As String
Dim CurrentCell As String
Dim ColumnNo As String
Dim ChartRange As Integer
' Defining a variable that increments to allow sheet renaming.
ChartNo = 1
' Trying to define a variable to use to move the column along.
ColumnNo = "A:A"
While ActiveCell.Value <> ""
Charts.Add
ActiveChart.ChartType = xlLine
' This is the line where I am having the problem, how can I replace the column letters with a variable that can be incremented to allow moving along two columns at a time..?? Remember that "A:A" is always the X-Axis.
ActiveChart.SetSourceData Source:=Sheets("sheet1").Range( _
"A:A, B:B, C:C"), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlRight
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Range("C1").Activate
FullCellRef = Left(ActiveCell.Value, 13)
Fruni = Right(Right(FullCellRef, 3), 2)
CellRef = Left(FullCellRef, 10) & Fruni
Sheets("Chart" & ChartNo).Name = CellRef
ActiveCell.Offset(0, 2).Select
ChartNo = ChartNo + 1
ColumnNo = ColumnNo + 2
Wend
End Sub
============================================
Thanks in advance for any help given.
I have a worksheet which comprises of a sheet of a lot of raw data from which I am trying to automate the creation of some charts. However, the amount of rows and columns can vary so here is my dilemma.
The charts always use the A column as the X-Axis but, the Y-Axis comprises of two adjacent columns which move along from chart to chart...e.g. B & C for the first one, D & E for the next and so on. I was thinking of writing a while loop searching for an empty column as it moves along (thus indicating the end) however, it is this moving along the columns which is causing the headache. The code I have so far is a little basic but, here is a cut and paste:
============================================
Sub Chart()
Dim ChartNo As Byte
Dim FullCellRef As String
Dim CellRef As String
Dim SheetName As String
Dim Fruni As String
Dim CurrentCell As String
Dim ColumnNo As String
Dim ChartRange As Integer
' Defining a variable that increments to allow sheet renaming.
ChartNo = 1
' Trying to define a variable to use to move the column along.
ColumnNo = "A:A"
While ActiveCell.Value <> ""
Charts.Add
ActiveChart.ChartType = xlLine
' This is the line where I am having the problem, how can I replace the column letters with a variable that can be incremented to allow moving along two columns at a time..?? Remember that "A:A" is always the X-Axis.
ActiveChart.SetSourceData Source:=Sheets("sheet1").Range( _
"A:A, B:B, C:C"), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlRight
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Range("C1").Activate
FullCellRef = Left(ActiveCell.Value, 13)
Fruni = Right(Right(FullCellRef, 3), 2)
CellRef = Left(FullCellRef, 10) & Fruni
Sheets("Chart" & ChartNo).Name = CellRef
ActiveCell.Offset(0, 2).Select
ChartNo = ChartNo + 1
ColumnNo = ColumnNo + 2
Wend
End Sub
============================================
Thanks in advance for any help given.