Consulting

Results 1 to 10 of 10

Thread: Solved: how can i get labelname in graphic

  1. #1
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location

    Solved: how can i get labelname in graphic

    I'm using Excell 2003.
    I have a range of data (sheet data). With these data i create a pivottable.
    These table i use to make a graphic.
    As labelname of the graphicpoints i like to use the name in label (column C)
    Now i manualy click on each value and then i point too the range in column c
    I think this may be easier using vba.
    There can be 1 problem because the number of rows can change depending on the values in the sheet data.
    I also looking for a solution for the pivottable. I now have a "hard" row reference to the cells a2:c30 but this can change to. How can i make the row range flexible (depending on the rows in the sheet data)

    please see the attached file.
    Thx for the help.

    Ger
    Attached Files Attached Files

  2. #2
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location

    how to make the source flexible?

    I succeeded to get the lablename in the graphic using vba. The problem i have is that the number of rows in the sheet "data" can change (now i "programmed" till row 30). how can i make this flexible. The same problem is the range I use for the graphic (now 8 points).
    And how can i provide the message when i delete the "old" sheet draaitabel (pls see attachement)
    Please help,

    Ger
    Attached Files Attached Files

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Macro3()
    Dim Lastrow As Long
    Dim i As Long

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row

    With .ChartObjects(1).Chart

    For i = 2 To Lastrow

    .SeriesCollection(i - 1).Points(1).DataLabel.Text = "=grafiek!R" & i - 1 & "C3"
    Next i
    End With
    End With

    ActiveWindow.Visible = False
    Windows("vlootschouw.xls").Activate
    Range("E12").Select
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    I had to change a few things but this is working fine:

    [VBA]Sub Macro4()
    Sheets("grafiek").Select
    Dim Lastrow As Long
    Dim i As Long

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row

    With .ChartObjects("grafiek 1").Chart

    For i = 2 To Lastrow
    ActiveSheet.ChartObjects("Grafiek 1").Activate
    ActiveChart.SeriesCollection(1).Points(i - 1).DataLabel.Select
    Selection.Text = "=grafiek!R" & i - 1 & "C3"
    Next i
    End With
    End With

    ActiveWindow.Visible = False
    Windows("vlootschouw.xls").Activate
    Range("E12").Select
    End Sub[/VBA]

    Thanks for the help.
    Can i use the same for a fexible range in the pivottable?

    Ger
    Last edited by Bob Phillips; 02-23-2011 at 07:23 AM. Reason: Added VBA tags

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why did you need to do that selecting, it worked perfectly well without in my tests?

    What do you mean by do the same for pivots, they are dynamic by nature.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    i had an error in the line:
    .SeriesCollection(i - 1).Points(1).DataLabel.Text = "=grafiek!R" & i - 1 & "C3"
    so i changed it to
    ActiveSheet.ChartObjects("Grafiek 1").Activate
    ActiveChart.SeriesCollection(1).Points(i - 1).DataLabel.Select
    Selection.Text = "=grafiek!R" & i - 1 & "C3"

    the pivottable gets it data from the sheet data. I make the pivottable with the range a2:c30. But this range (row 30) can change.


    Ger

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    For the pivot, createa a defined name of say MyData with RefersTo of Offset(data!$A$2,0,0,COUNTA(data!$A:$A),3) and set the PT data to MyData.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    xld, thanks a lot for your help again. It works fine now.
    I have 1 question: is it necessary to use the "i" in "Next i" (see macro4)

    Ger


  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not necessary, but it is a good programming practice (multiple nested loops are better identified, not all languages are so loose).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    Thanks.

    Ger

Posting Permissions

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