I tried deleting the graph and adding a new one, but the new one is exhibiting the same behavior. I am manipulating the graph by code, shown below. Don't be put off by the length, it is well commented.
Public Sub UpdateDifferencesGraphData(strInv1 As String, strInv2 As String, strInv3 As String, strAmort As String, _
strNR1 As String, strNR2 As String, strNR3 As String)
'The purpose of this procedure is to clear out the existing graph data from the Differences Graph Data sheet and then
'transfer the imported pricing data into the Differences Graph Data sheet, and lastly fill the labels for the graph
'which lie on the Differences Graph Data sheet.
'Declare local variables.
Dim i As Integer
'Initialize Variables.
i = 3
'Working with the Difference Graph Data sheet.
With Sheets("Differences Graph Data")
'Activate the sheet.
.Activate
'Clear the existing graph data.
.Range(Cells(3, 1), Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 7)).ClearContents
'Put the Date header in.
.Cells(2, 1).Value = "Date"
End With
'Working with the table sheet that was imported from Access.
With Sheets("tbl_Graph_Data_Differences")
'Copy the used range, minus the header.
.UsedRange.Offset(1, 0).Copy Destination:=Sheets("Differences Graph Data").Cells(3, 1)
'Turn off alerts so the user isn't warned about deleting the sheet.
Application.DisplayAlerts = False
'Delete the sheet because we are finished with it.
.Delete
'Turn alerts back on.
Application.DisplayAlerts = True
End With
'Working with the Difference Graph sheet again.
With Sheets("Differences Graph Data")
'Clear all rows that have no data except the date.
Do Until i >= .Cells(Rows.Count, 1).End(xlUp).Row + 1
'If the sum of the row is equal to the date value, then it has no other data in it.
If WorksheetFunction.Sum(.Rows(i)) = .Cells(i, 1).Value Then
'Delete the row.
.Rows(i).Delete
'We need to check the next row which just moved up.
i = i - 1
End If
i = i + 1
Loop
'Put the Amortization as the header.
.Cells(1, 1).Value = strAmort & " Price Differences"
'If Investor 2 and Note Rate 1 exist.
If strInv2 <> "" And strNR1 <> "0.000" Then
'Put the Investor and note rate into the header for this column of data.
.Cells(2, 2).Value = "Generic / " & strInv2 & " " & strNR1 & "% Difference"
'Make sure the column is not hidden.
.Columns(2).Hidden = False
Else
'If the note rate has not been populated, hide the column.
.Columns(2).Hidden = True
End If
'If Investor 2 and Note Rate 2 exist.
If strInv2 <> "" And strNR2 <> "0.000" Then
'Put the Investor and note rate into the header for this column of data.
.Cells(2, 3).Value = "Generic / " & strInv2 & " " & strNR2 & "% Difference"
'Make sure the column is not hidden.
.Columns(3).Hidden = False
Else
'If the note rate has not been populated, hide the column.
.Columns(3).Hidden = True
End If
'If Investor 2 and Note Rate 3 exist.
If strInv2 <> "" And strNR3 <> "0.000" Then
'Put the Investor and note rate into the header for this column of data.
.Cells(2, 4).Value = "Generic / " & strInv2 & " " & strNR3 & "% Difference"
'Make sure the column is not hidden.
.Columns(4).Hidden = False
Else
'If the note rate has not been populated, hide the column.
.Columns(4).Hidden = True
End If
'If Investor 3 and Note Rate 1 exist.
If strInv3 <> "" And strNR1 <> "0.000" Then
'Put the Investor and note rate into the header for this column of data.
.Cells(2, 5).Value = "Generic / " & strInv3 & " " & strNR1 & "% Difference"
'Make sure the column is not hidden.
.Columns(5).Hidden = False
Else
'If the note rate has not been populated, hide the column.
.Columns(5).Hidden = True
End If
'If Investor 3 and Note Rate 2 exist.
If strInv3 <> "" And strNR2 <> "0.000" Then
'Put the Investor and note rate into the header for this column of data.
.Cells(2, 6).Value = "Generic / " & strInv3 & " " & strNR2 & "% Difference"
'Make sure the column is not hidden.
.Columns(6).Hidden = False
Else
'If the note rate has not been populated, hide the column.
.Columns(6).Hidden = True
End If
'If Investor 3 and Note Rate 3 exist.
If strInv3 <> "" And strNR3 <> "0.000" Then
'Put the Investor and note rate into the header for this column of data.
.Cells(2, 7).Value = "Generic / " & strInv3 & " " & strNR3 & "% Difference"
'Make sure the column is not hidden.
.Columns(7).Hidden = False
Else
'If the note rate has not been populated, hide the column.
.Columns(7).Hidden = True
End If
End With
End Sub
Explanation of code:
Clear off previous graph data. Paste new graph data from results that have been exported onto a sheet from Access. Delete that sheet from Access. If any rows have no data, delete them. Set the graph header, gotten from cell 1,1 of the table. Check each column for data. If none is present, hide the column so it will not be graphed. The reason for this is the user is given an option to show up to 6 sets of data on the graph, and if they choose to do less than 6 but the columns are not hidden, the series markers will show up in the legend.
Thanks Andy
Bookmarks