Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:38:20+00:00 2026-06-16T02:38:20+00:00

I have the following data Name Date Number_of_apples ——————————- abc 1-1-2012 5 abc 2-1-2012

  • 0

I have the following data

Name Date      Number_of_apples
-------------------------------
abc  1-1-2012  5
abc  2-1-2012  3
xyz  1-1-2012  4
xyz  2-1-2012  2
xyz  3-1-2012  6

I want to plot a 2D line graph in excel representing the above data.

Graph should contain Date in X axis and Number of apples in Y axis.

Example plot for name abc :

enter image description here

Depending on selection of name, the graph should update to represent data for that name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:38:22+00:00Added an answer on June 16, 2026 at 2:38 am

    This worked for me. Some notes:

    1. This code needs to be placed in a Worksheet module
    2. To update the chart simply click the name in your name column e.g. ‘xyz’, ‘abc’ etc.
    3. If no chart is present it creates one first and then subseqently updates that same chart

    Here’s the code:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Intersect(Target, Range("A:A")) Is Nothing Then
            UpdateChart Target
        End If
    End Sub
    
    Sub UpdateChart(name As Range)
        Dim startRow As Integer, lastRow As Integer
        Dim namerng As Range, data As Range, applechart As ChartObject
    
        Set namerng = Range("A1:A" & Range("A1").End(xlDown).Row)
    
        startRow = WorksheetFunction.Match(name.Value, namerng, 0)
        lastRow = startRow + WorksheetFunction.CountIf(namerng, name.Value) - 1
    
        On Error Resume Next
        Set applechart = ActiveSheet.ChartObjects("AppleChart")
        Set data = Range("B" & startRow & ":C" & lastRow)
    
        If Not applechart Is Nothing Then
            applechart.Activate
            ActiveChart.SetSourceData Source:=data
        Else
            ActiveSheet.Shapes.AddChart.Select
            ActiveSheet.ChartObjects(1).name = "AppleChart"
            ActiveChart.ChartType = xlLine
            ActiveChart.SetSourceData Source:=data
        End If
    End Sub
    

    Edit: How to set-up in Excel

    1. In Excel press ALT + F11. This opens the VBA editor
    2. In the left hand project window click the worksheet where your data is held e.g. Sheet1
    3. In the left hand dropdown select Worksheet
    4. In the right hand dropdown select SelectionChange
    5. Cut and paste the code

    Note – I am assuming your data starts in column A. If not you’ll need to amend the column references in the code yourself

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following sample data with duplicate information: ID Date Emp_ID Name Keep
SQL Server 2005+. I have a table with the following schema/data: Name Slots Date
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have a table emp with following structure and data: name dept salary -----
Lets say i have a table with the following data Customer table: Name amount
I have to parse the following data {ResultSet:{Query:microsec fin,Result: [{symbol:MICROSE_a.NS,name: MICROSEC FIN SERV LTD
I have an xml like the following <DataCollection> <Data> <Name>John</Name> <Age>30</Age> </Data> ... more
I have following data frames > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14
I have a table with following columns (name : varchar), (mydate : DATE), (endtime
I have an array with the following format: [NSArray arrayWithObjects: [NSArray arrayWithObjects:@number,@name,@date,@about,nil], [NSArray arrayWithObjects:@number,@name,@date,@about,nil],

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.