LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default A QueryTable refresh, a named range, the 'Hidden' property

Here is a stumper.

Given:
In a single Workbook, WB1, I have two Worksheets, WS1 and WS2.
In WS1 I have a QueryTable, QT1, with the following properties:
is a Text file import, tab delimited, etc.
refreshes on file open
does NOT refresh periodically
DOES allow manual refresh
is set to "Overwrite existing cells with new data, clear unused
cells".
cells."

In addition to the named Range that Excel creates for QT1, I have a named
Range, N1, that refers to a single column of the data imported by QT1. I
adjust N1.RefersTo in QT1_AfterRefresh as follows:

'Update N1 to span column A of QT1.
Private Sub QT1_AfterRefresh(ByVal Success As Boolean)
Dim Query_Data_Count, First_Data_Row, Last_Data_Row
'QT1 is declared and set in my 'Events' Class Module.

Query_Data_Count = QT1.ResultRange.Rows.Count
First_Data_Row = IMP3_QT.ResultRange.Row
Last_Data_Row = Query_Data_Count + First_Data_Row - 1

Application.Names("N1").RefersTo = "='" + WS1.Name + "'!$A$" +
CStr(First_Data_Row) + ":$A$" + CStr(Last_Data_Row)
End Sub

Moreover, in Module1 I have the following function:

'Count the visible rows.
Function Visible_Count (R As Range) As Long
Dim C As Range, Count As Long
For Each C in R
If Not C.EntireRow.Hidden Then 'The Error is raised here. Using
SpecialCells() raises the same error.
Count = Count + 1
End If
Next C
Visible_Count = Count
End Function


In some cell in WS2 I have the formula:
=Visible_Count(N1)


Here is the problem: when I open the file Excel executes =Visible_Count(N1)
which raises Error 1004 (Unable to get the Hidden property of the Range
class) at the marked line. Here is the rub: when I then manually calculate
the cell, the error is not raised and I get the correct value. Furthermore,
after manual calculation, I can execute filters on Column A of the data
import and the formula works perfectly. If I manually refresh the data, the
error is raised.

I have worked around the problem by turning off automatic calculation in
QT1_BeforeRefresh, and turning it back on at the end of QT1_AfterRefresh.
But I would like to address the underlying problem, if possible. Does it
have something to do with asynchronous/synchronous query refreshing? Or
perhaps with the "Overwrite existing cells..." property? Or perhaps the
range is somehow disabled as the query is refreshed?

Please help. Thanks!



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Query Refresh Based on Dynamic Named Range bwilk77 Excel Discussion (Misc queries) 0 May 26th 09 02:17 PM
Delete Hidden Named Range Scott Excel Discussion (Misc queries) 3 July 24th 08 09:40 PM
Named range is hidden when using OFFSET() Conan Kelly Excel Discussion (Misc queries) 1 October 8th 07 08:56 PM
1004 - Unable to set the hidden property of the range class Tim Whitley Excel Programming 3 February 20th 06 09:50 PM
How to check if SHEET has QUERYTABLE property ? steve Excel Programming 1 August 22nd 03 06:19 PM


All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"