Excel chart returning too many ranges (sometimes)

时间:2017-11-13 06:44:09

标签: excel-vba vba excel

Background: I have a workbook with several worksheets each with the same structure. Each worksheet has several sets of columns all of the same structure. Each set of columns 4 columns containing a heading and 100+ rows of data (always the same number of rows for all columns).

Goal: I need to produce a line chart for every set of columns on every sheet.

Macro: One subroutine creates a chart for a single set of rows. A calling routine sets the top left corner, calls the chart routine and then moves 7 columns to the right until that cell is empty. The outer routine clears all charts on a sheet and then calls this repeatedly for each sheet.

Problem: Macro is tested and working on test workbook with 2 sheets in it. When I deploy to "real" book it works for 1 or 2 sheets and then suddenly starts selecting crazy numbers of ranges for subsequent sheets so the chart is wrong and unreadable. This is repeatable and consistent - e.g. for the 3rd sheet it doe sit wrong no matter how many times I run it.

The weird bit: when I run the macro through debug, it works flawlessly. And then when I run it at full speed it works for any sheets that I ran through the debugger. Once a sheet is "fixed" it seems to work but other sheets don't.

Help?

TL;DR: a tested macro is suddenly selecting too many ranges for some worksheets but not others. When I watch it for errors, it works.

0 个答案:

没有答案