+ Reply to Thread
Results 1 to 5 of 5

VBA Macro erroring out with example code / document

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    VBA Macro erroring out with example code / document

    Hey ExcelForum,

    My following code below keeps erroring out at the line: GetTopRange = URng.Address but I can't figure out why and what's going wrong, I've attached an example below please see

    Please Login or Register  to view this content.
    Hopefully someone can help me with my problem.

    Thanks
    Attached Files Attached Files
    Last edited by Hyflex; 02-25-2014 at 08:04 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA Macro erroring out with example code / document

    Hi,

    Any chance that
    Please Login or Register  to view this content.
    should actually say
    Please Login or Register  to view this content.
    ???

    Stepping through the code, the first location is "London", but the first row that is being looked at is the header row (row 3). And changing the 3 to a 4 does get the code past this point.

    Some other changes you will need to make:
    1. In the "CreateCharts" subroutine, you will need to change GroupRange = to Set GroupRange =, and similarly for ValueRange = on the next line.
    2. In the "AddChart" subroutine, you will have to add your series manually. The reason for this is because when using SetSourceData in your case, Excel is unable to recognise chartable data in the range that you have given it, so it creates the chart without an initial series. This also means the chart doesn't have any other features either... no plot area, no legend, and no placeholder for a title. So the code errors out when you try to set the title, because the title placeholder doesn't exist. You can change this by manually adding each series in VBA rather than trying to set the source data.

    I hope this has helped

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: VBA Macro erroring out with example code / document

    There's something wrong with the structure of your IF..Then.. Else blocks; however, notice
    (1) that URng is never initialized
    (2) the first time through the loop, Cell.Value= "Location" but StrLine="London" therefore, the test evaluates to False and immediately exits to GetTopRange = URng.Address [see (1)]

    Please Login or Register  to view this content.
    Last edited by protonLeah; 02-25-2014 at 03:40 AM.
    Ben Van Johnson

  4. #4
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: VBA Macro erroring out with example code / document

    Thanks guys, the fixed code is:

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA Macro erroring out with example code / document

    No worries.

    Please don't forget to mark this thread as solved and please click on the * next to my post to say thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro Code for multi-user .xlsm document
    By maheshle in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2012, 03:20 PM
  2. Print macro erroring if there are hidden sheets
    By davidjoe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2012, 03:51 PM
  3. add something to m code to keep from erroring
    By daniels012 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2009, 09:55 AM
  4. Basic Macro (Jump to Cell) erroring out
    By kethyar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2008, 06:54 PM
  5. VBA code erroring in XL97...
    By sharpie23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2006, 03:30 PM

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