chart in excel

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

I want to draw a chart inside the excel
My problem is I do not know how to set credit , debit ,balance the horizontal part
And set total credit , debit ,balance of the vertical part as shown below

1351210.png


rows balance

For I = 2 To excelWorksheet.UsedRange.Rows.Count
If String.IsNullOrEmpty(excelWorksheet.Range("b" & I).Value) = False AndAlso String.IsNullOrEmpty(excelWorksheet.Range("c" & I).Value) = False Then
excelWorksheet.Range("d" & I).Value = "=b" & I & "-c" & I
End If
Next

column total

excelWorksheet.Range("b" & lRow + 1).Value = "=SUM(b2:b" & lRow & ")"
excelWorksheet.Range("c" & lRow + 1).Value = "=SUM(c2:c" & lRow & ")"
excelWorksheet.Range("d" & lRow + 1).Value = "=SUM(d2:d" & lRow & ")"
excelWorksheet.Range("a" & lRow + 1).Value = "total"

ful code

Dim oChart As Excel.Chart
Dim MyCharts As Excel.ChartObjects
Dim MyCharts1 As Excel.ChartObject
MyCharts = excelWorksheet.ChartObjects
MyCharts1 = MyCharts.Add(250, 30, 400, 250)
oChart = MyCharts1.Chart

With oChart
'set data range for chart
Dim chartRange As Excel.Range
chartRange = excelWorksheet.Range("b1", "d3")
.SetSourceData(chartRange)
'set how you want to draw chart i.e column wise or row wise
.PlotBy = Excel.XlRowCol.xlColumns
'set data lables for bars
.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowNone)
'set legend to be displayed or not
.HasLegend = True
'set legend location
.Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
'select chart type
end with

Continue reading...
 
Back
Top