xcel VBA Chart counting and formatting

0 votes

I want to develop a macro that counts the number of charts inside a specified range and then takes different actions based on the number. How would I change activesheet.chartobjects.count such that it only counts within a range rather than throughout the entire sheet?

Here's the skeleton of my code.

Sub chrt_chck()
    Dim rng As Range
    Dim x As Long
    Set rng = Range("A1:F10")
    x = ActiveSheet.rng.ChartObjects.Count
    
    If x > 1 Then
    'select and delete all charts in range
    End If
    
    If x = 1 Then
    'select that chart and update format
    Else
    'create chart and set format
    End If
End Sub
Oct 31, 2022 in Others by Kithuzzz
• 38,000 points
405 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
The arrChO is a zero-based array and x must count the charts... K is initially 0. I could use X - 1 here, but I got used to have a separate variable for that. Sometimes, there are conditional iterations where it is good to use something easy to be checked at the end, if necessary, without being confused by the iterated variable. I can say, it is a matter of habit... A good habit, I would (still) dare to believe... :) I could also declare array 1 To ActiveSheet.ChartObjects.count, also.
answered Oct 31, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Others

0 votes
1 answer

Excel VBA if file closed, then open and paste, else just paste data

Slightly re-worked to add full workbook/sheet qualifiers ...READ MORE

answered Sep 21, 2022 in Others by narikkadan
• 63,600 points
1,392 views
0 votes
1 answer

VBA, Query Vertica database and populate to excel

You can query Vertica directly from excel. I ...READ MORE

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

Thousand and million formatting for negative numbers (excel/ googlesheets)

Its not possible. What you could do is ...READ MORE

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

Creating a chart in VBA with 2 different Types

Can you carry this out by hand ...READ MORE

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

How can I find and replace text in Word using Excel VBA?

Try this code Option Explicit Const wdReplaceAll = 2 Sub ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,600 points
5,410 views
0 votes
1 answer

Create a pie chart of ages, showing under 30's, 30-50's, and over 50's

Two things: A pie chart does not aggregate ...READ MORE

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

How to modify Powerpoint Chart ChartData by Excel VBA

Example: Code: Set pptApp = GetObject(, "PowerPoint.Application") Set pptPres = ...READ MORE

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

Name for excel graph problem with the vba generator

Change the name of the workbook : Sub Macro_name_graph2() ...READ MORE

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

Automating production of graphs using VBA

You have to change: chrtname = Cells(i, 2).Value To: chrtname ...READ MORE

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

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,456 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