Results 1 to 2 of 2

Thread: Excel chart using macro

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    3

    Excel chart using macro

    hi all,
    im writing a macro to generate an excel chart.im new to macro and chart.with the following coding im able to get values for the y axis, but not the values for x axis.can anyone help with this?
    VB Code:
    1. Public Sub Reports()
    2. Sheet2.Cells(2, 1).Value = ""
    3. Sheet2.Cells(2, 2).Value = ""
    4. Sheet2.Cells(2, 3).Value = ""
    5. Sheet2.Activate
    6.  
    7. Set objconn = New ADODB.Connection
    8. objconn.Open "ivrserver", "sa", ""
    9. Dim rs As Recordset
    10. Dim DaySec As Long, nDateDiff As Long, iDCnt As Long
    11. Dim TempEdTime As String, TempStTime As String
    12.  
    13. Set ors = New ADODB.Recordset
    14. StrSql = "SELECT distinct(CalledID),Count(*)[TotalCalls] FROM CallLogSummary WHERE CallTime >= " & p1 & " AND EndTime <= " & p2
    15. If CalledID <> "" Then
    16. StrSql = StrSql & " and CalledID in (" & CalledID & ")"
    17. End If
    18. '''If callType <> "" Then
    19. '''StrSql = StrSql & " and callType in (" & callType & ")"
    20. '''End If
    21. '''If IVRFlow <> "" Then
    22. '''StrSql = StrSql & " and ApplicationName in ('" & IVRFlow & "')"
    23. '''End If
    24. StrSql = StrSql & " group by Calledid"
    25. ors.Open StrSql, objconn
    26.  
    27. lngCurRow = 1
    28. lngCurCol = 0
    29.  
    30. If Not ors.EOF Then
    31. ors.MoveFirst
    32. While Not ors.EOF
    33. RecCnt = RecCnt + 1
    34. ors.MoveNext
    35. Wend
    36. ors.MoveFirst
    37. If RecCnt > 100 Then
    38. Temp = RecCnt - 100
    39. End If
    40.  
    41. For i = 1 To Temp
    42. ors.MoveNext
    43. Next i
    44. End If
    45.  
    46. ActiveSheet.Range("a1" & ":a" & (RecCnt)).Columns.Select
    47.  
    48.  
    49. Set rptchart = Excel.Charts.Add
    50. ors.MoveFirst
    51. While Not ors.EOF
    52. 'Activesheet.Cells(lngCurRow, 1) = ors("LineID")
    53. Sheet2.Cells(lngCurRow, 2) = ors("CalledId")
    54. lngCurRow = lngCurRow + 1
    55. ors.MoveNext
    56. Wend
    57. ors.MoveFirst
    58. While Not ors.EOF
    59. lngCurCol = lngCurCol + 1
    60. Sheet2.Cells(lngCurCol, 1) = ors("TotalCalls")
    61. ' Sheet2.Cells(1, lngCurCol) = ors("TotalCalls")
    62. ors.MoveNext
    63. Wend
    64.  
    65. With rptchart
    66. .PlotBy = xlRows
    67. .HasTitle = True
    68. .ChartTitle.Caption = "Number of Calls in each CalledID"
    69. .ChartTitle.Font.Size = 12
    70. .ChartTitle.Font.Bold = True
    71.  
    72. .Axes(xlCategory, xlPrimary).HasTitle = True
    73. .Axes(xlCategory).AxisTitle.Text = "Called ID"
    74.  
    75. .Axes(xlValue, xlPrimary).HasTitle = True
    76. .Axes(xlValue).AxisTitle.Text = "Total Calls"
    77. End With
    78.  
    79. rptchart.Activate
    80. Exit Sub
    81. errhand:
    82. MsgBox "Error No : " & Err.Number & ",Description : " & Err.Description & ",Source : " & Err.Source
    83. End Sub
    Last edited by Hack; Apr 28th, 2006 at 09:01 AM. Reason: Added [vbcode] [/vbcode] tags for more clarity.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel chart using macro

    Excel VBA question moved to Office Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width