Insert pie chart in Excel macro function

0 votes

I'm new to using macros. I've been attempting to use an Excel macro tool to insert a pie chart on the Subject name fields (X, Y, and Z). When the user clicks a macro command button, this graph should be able to be drawn. In essence, it should count, and then produce the chart using the result.

Here is an example of current data:

Channel_Type | Channel_Category | Category | **Subject_Name**
  MICROBLOG          General         A           X
   Forum             General         A           Z
   BLOG              General         A           Y
   FORUM             General         A           X
  MICROBLOG          General         A           Z
   BLOG              General         A           Z

Here is the desired outcome:

X : 2 | Y : 1 | Z : 3

enter image description here

This is what i tried before to plot the graph for the whole sheet but i am unsure of how to just select one column:

Option Explicit

Sub Example()
Dim cht As ChartObjects
For Each cht In Worksheets(1).ChartObjects

Next cht
cht.Chart.ChartType = xlPie


End Sub
Oct 14, 2022 in Others by Kithuzzz
• 38,000 points
1,143 views

1 answer to this question.

0 votes
Think about arranging your data in a table with a count column at the very end. If you enter =1 here, it will automatically fill in the values for each row (assuming that each row has a unique record). Use the "Subject name" and "count" variables to create a pivot chart (pie chart). If you must use VBA, you can then link the pivottable's refresh to a command button, which will cause the chart to update whenever the button is pressed. Because the data is in an Excel table, it will also add new rows as they are added.
answered Oct 14, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How do I use the Indirect Function in Excel VBA to incorporate the equations in a VBA Macro Function

Try this: Sub Test() Dim str As String: str ...READ MORE

answered Jan 19, 2023 in Others by narikkadan
• 63,600 points
1,037 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
3,721 views
0 votes
1 answer

IF function in combination with an Round function Excel

I'm not sure if it is a ...READ MORE

answered Sep 25, 2022 in Others by narikkadan
• 63,600 points
3,538 views
0 votes
1 answer

How to use the INDIRECT function in Excel

Try this: =INDEX(INDIRECT($A$1&"!$1:$1048576"),MATCH($B$1,INDI ...READ MORE

answered Sep 29, 2022 in Others by narikkadan
• 63,600 points
889 views
0 votes
0 answers

Convert Rows to Columns with values in Excel using custom format

1 I having a Excel sheet with 1 ...READ MORE

Feb 17, 2022 in Others by Edureka
• 13,690 points
975 views
0 votes
1 answer

Remove formulas from all worksheets in Excel using VBA

Try this : Option Explicit Sub test1() ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
2,019 views
0 votes
1 answer

Calculate monthly average from daily data without PivotTable

Assuming you have the months in column D enter ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
1,764 views
0 votes
1 answer

Automate compound annual growth rate (CAGR) calculation

The following PowerPivot DAX formulas worked for ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 63,600 points
1,280 views
0 votes
1 answer

Excel Pie-Chart in categories

create a pivot pie chart. You can manually ...READ MORE

answered Oct 8, 2022 in Others by narikkadan
• 63,600 points
1,121 views
0 votes
1 answer

Creating an unique export data VBA Macro Function in Excel

Unfortunately, the tables will vary in size. ...READ MORE

answered Nov 14, 2022 in Others by narikkadan
• 63,600 points
792 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP