Sub scatter_plot_with_labels_in_Excel() ' ' Antonio Jesús Sánchez Fuentes, Universidad Pablo de Olavide ' Date: January, 2007 ' ' Instructions: Copy all the text and paste in the VBA editor. ' Dim provisional As Worksheet Dim etiquetas As Range libro_activo = Application.InputBox("El nombre del libro donde quieres hacer el gráfico") Set provisional = Workbooks(libro_activo).Sheets.Add(Type:=xlWorksheet) valores_x = Application.InputBox("Los valores del eje X", Type:=0) valores_y = Application.InputBox("Los valores del eje Y", Type:=0) nombre_serie = Application.InputBox("El nombre de la serie", Type:=2) Set etiquetas = Application.InputBox( _ "Identificadores de cada elemento de la serie", Type:=8) num_etiquetas = etiquetas.Count ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Workbooks(libro_activo).Activate ' Graph creation Charts.Add ActiveChart.ChartType = xlXYScatter ActiveChart.SetSourceData Source:=etiquetas, _ PlotBy:=xlRows ActiveChart.SeriesCollection(1).XValues = valores_x ActiveChart.SeriesCollection(1).Values = valores_y ActiveChart.SeriesCollection(1).Name = nombre_serie ActiveChart.Location Where:=xlLocationAsNewSheet 'XlChartLocation With ActiveChart .HasTitle = False .Axes(xlCategory, xlPrimary).HasTitle = False .Axes(xlValue, xlPrimary).HasTitle = False End With ' Labels substitution ActiveChart.SeriesCollection(1).Select ActiveChart.SeriesCollection(1).ApplyDataLabels Type:=xlDataLabelsShowValue, _ AutoText:=True, LegendKey:=False ActiveChart.SeriesCollection(1).DataLabels.Select For i = 1 To num_etiquetas ActiveChart.SeriesCollection(1).Points(i).DataLabel.Select Selection.Characters.Text = etiquetas(i, 1) Next ActiveChart.ChartArea.Select ' Drop the worksheet introduced. provisional.Delete ' Save the file Workbooks(libro_activo).Save End Sub