error in active chart - why?

earp_

Active Member
Joined
Apr 30, 2008
Messages
305
Hi,
in sheet2 i have some cells which are update dynamically, and in sheet3 i have a chart which is updated by values that are in sheet2

everything works good if i'm on sheet2 (sheet2 active)

but if i click on sheet3 and i wait for the IF case i've got an error.
why?
local Variable
Sub macro1()
Dim pIndex As String
pIndex contains A after a while B and so on...
...
If WorksheetFunction.CountA(Sheets("Sheet2").Columns(pIndex)) > 1
I have no problem also if i'm in another sheet that is not a chart
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You can't use WorksheetFunction if the activesheet is not a worksheet.
 
Upvote 0
so what do you suggest me?
I mean if I want to see sometimes the chart without having errors...
 
Upvote 0
Sorry, what I just said is incorrect. It's the combination of Columns and the activesheet not being a worksheet. If you use:
Code:
If WorksheetFunction.CountA(Sheets("Sheet2").Range(pIndex & ":" & pIndex)) > 1
you should be OK.
 
Upvote 0
Do you have the word 'Then' on the end of that line? (I assumed you just left it out of what you posted originally since you said it worked sometimes)
 
Upvote 0
That's interesting Rory - any idea why ?
None whatsoever! :) though I am researching it now - it must have come up before, unless I am completely wrong!

(I realise this is probably akin to asking why water is wet)
Not really - I'm sure I could get a £250k grant to research that! ;)
 
Upvote 0
More specifically, the problem seems to be using Columns(column_letter) when the activesheet is not a worksheet. If you use Columns(column_number) then it's fine.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top