Boa tarde, estou com dificuldade, fiz uma planilha dinâmica, onde o gráfico é inserido via VBA,
Mas o Grafico não aparece no local onde desejo, gostaria de saber qual o comando que devo utilizar para que o grafico apareca.
segue o codigo que fiz, repare que ja seleciono o E1 antes de chamar o grafico, mas isso não adiantou.
Sub CriarGrafico()
Application.ScreenUpdating = False
'GERANDO LISTA
Sheets("P_LOCALIDADES").Select
Range("A1:B65000").Select
Selection.ClearContents
Range("E1:E65000").Select
Selection.ClearContents
'SELECIONANDO COLUNA ONDE IREMOS EXTRAIR OS DADOS.
Sheets("COLAR AQUI").Select
Columns("D:D").Select
Selection.Replace What:="", Replacement:="Não preenchido", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("COLAR AQUI").Range("D:D").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("P_LOCALIDADES").Range("A1"), Unique:=True
Sheets("P_LOCALIDADES").Select
'PROCURANDO A ULTIMA LINHA
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Range("B2").Select
'CONTANDO VALORES
ActiveCell.FormulaR1C1 = "=COUNTIF('COLAR AQUI'!C[2],P_LOCALIDADES!C[-1])"
Selection.AutoFill Destination:=Range("B2:B" & LastRow)
'COLOCANDO VALORES EM ORDEM
ActiveWorkbook.Worksheets("P_LOCALIDADES").Sort.SortFields.Add Key:=Range("B2") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("P_LOCALIDADES").Sort
.SetRange Range("A2:B123")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("e2").Select
'CRIANDO GRAFICOS
Sheets("P_LOCALIDADES").Select
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Range("A13").Select
Range("A13:B" & LastRow).Select
Selection.Copy
Range("A14").Select
ActiveSheet.Paste
Range("A13").Select
ActiveCell.FormulaR1C1 = "Outros"
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Range("b13").Select
ActiveCell.FormulaR1C1 = "=Sum(R[1]C[0]:R[30]C[0])"
Range("e1").Select
ActiveSheet.Shapes.AddChart2(251, xl3DPieExploded).Select
ActiveChart.SetSourceData Source:=Range("P_LOCALIDADES!$A$2:$B$13")
ActiveChart.ChartTitle.Text = "PRINCIPAIS LOCALIDADES"
ActiveChart.ApplyLayout (6)
'CRIANDO LISTA
Range("E21").Select
ActiveCell.FormulaR1C1 = "=IFERROR(Concat2(R[-7]C[-4]:R[-4]C[-3],""|""),"""")"
Range("E22").Select
ActiveCell.FormulaR1C1 = "=IFERROR(Concat2(R[-4]C[-4]:R[2]C[-3],""|""),"""")"
Range("E23").Select
ActiveCell.FormulaR1C1 = "=IFERROR(Concat2(R[3]C[-4]:R[8]C[-3],""|""),"""")"
Range("E24").Select
ActiveCell.FormulaR1C1 = "=IFERROR(Concat2(R[9]C[-4]:R[20]C[-3],""|""),"""")"
'FORMATAÇÃO
Range("A:A,B:B").Select
Range("B1").Activate
With Selection.Interior
.PatternColorIndex = 2
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
Range("A1").Select
Selection.Font.Bold = True
Columns("A:A").Select
Selection.Font.Italic = True
Application.ScreenUpdating = True
End Sub
Postado : 18/09/2016 1:32 pm