+ Reply to Thread
Results 1 to 2 of 2

What is wrong with this?

  1. #1
    Registered User
    Join Date
    08-07-2005
    Posts
    1

    What is wrong with this?

    I want to write a function which loops through a column and creates a chart.
    for some reason it isnt working and it dont gives an error at all.

    any ideas what is wrong?

    ---cut---
    Sub DiagrammErstellen()

    Dim oldi
    oldi = 2

    For i = 2 To Application.WorksheetFunction.CountA("A:A") Step 10

    Charts.Add
    ActiveChart.SetSourceData Source:=Sheets("Tabelle1").Range(oldi + ":" + i + "," + oldi + ":" + i + "")
    'ActiveChart.SetSourceData Source:=Sheets("Tabelle1").Range("A2:A7,B2:B7")
    ActiveChart.Location Where:=xlLocationAsNewSheet
    Charts.Add

    oldi = i
    Next
    End Sub

    ---cut---

  2. #2
    Bob Umlas
    Guest

    Re: What is wrong with this?

    For starters, Application.WorksheetFunction.CountA("A:A") is counting the
    literal string "A:A", not the RANGE!
    Try
    Application.WorksheetFunction.CountA(Range("A:A") )
    Next, this assumes that a worksheet is active, and after 1st time thru the
    loop, this is no longer true. Perhaps you need
    Application.WorksheetFunction.CountA(Sheets(1).Range("A:A") )
    ....
    just for starters.
    Bob Umlas
    Excel MVP

    "A.S." <[email protected]> wrote in message
    news:[email protected]...
    >
    > I want to write a function which loops through a column and creates a
    > chart.
    > for some reason it isnt working and it dont gives an error at all.
    >
    > any ideas what is wrong?
    >
    > ---cut---
    > Sub DiagrammErstellen()
    >
    > Dim oldi
    > oldi = 2
    >
    > For i = 2 To Application.WorksheetFunction.CountA("A:A") Step 10
    >
    > Charts.Add
    > ActiveChart.SetSourceData Source:=Sheets("Tabelle1").Range(oldi +
    > ":" + i + "," + oldi + ":" + i + "")
    > 'ActiveChart.SetSourceData
    > Source:=Sheets("Tabelle1").Range("A2:A7,B2:B7")
    > ActiveChart.Location Where:=xlLocationAsNewSheet
    > Charts.Add
    >
    > oldi = i
    > Next
    > End Sub
    >
    > ---cut---
    >
    >
    > --
    > A.S.
    > ------------------------------------------------------------------------
    > A.S.'s Profile:
    > http://www.excelforum.com/member.php...o&userid=26003
    > View this thread: http://www.excelforum.com/showthread...hreadid=393646
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1