PC Review


Reply
Thread Tools Rate Thread

Counting visible cells

 
 
Otto Moehrbach
Guest
Posts: n/a
 
      24th Nov 2006
Excel XP, Win XP
Helping an OP.
I have a range with numerous hidden columns.
The hidden columns are not contiguous.
Columns A:B are always visible.
I want to count the number of visible columns.
Row 4 is the header row, so I want to count the number of visible cells in
Row 4.
I use the following code to give me that count. I get an error on this
line.
The error message is "Unable to get the SpecialCells property of the range
class."
ColCount = Range("A4", Cells(4, Columns.Count).End(xlToLeft)) _
.SpecialCells(xlCellTypeVisible).Count
This seems simple to do. What am I doing wrong? Thanks for your time.
Otto


 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      24th Nov 2006
I can't reproduce it Otto.

I protected the sheet, tried a row with no data , a row with no data and no
hidden columns, nothing failed.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:OkenrX$(E-Mail Removed)...
> Excel XP, Win XP
> Helping an OP.
> I have a range with numerous hidden columns.
> The hidden columns are not contiguous.
> Columns A:B are always visible.
> I want to count the number of visible columns.
> Row 4 is the header row, so I want to count the number of visible cells in
> Row 4.
> I use the following code to give me that count. I get an error on this
> line.
> The error message is "Unable to get the SpecialCells property of the range
> class."
> ColCount = Range("A4", Cells(4, Columns.Count).End(xlToLeft)) _
> .SpecialCells(xlCellTypeVisible).Count
> This seems simple to do. What am I doing wrong? Thanks for your time.
> Otto
>
>



 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      24th Nov 2006
Sub sistance()
Dim c As Integer
For c = 1 To 256
If Columns(c).EntireColumn.Hidden = True Then
colcount = colcount + 1
End If
Next
MsgBox (colcount)
End Sub

--
Gary's Student


"Otto Moehrbach" wrote:

> Excel XP, Win XP
> Helping an OP.
> I have a range with numerous hidden columns.
> The hidden columns are not contiguous.
> Columns A:B are always visible.
> I want to count the number of visible columns.
> Row 4 is the header row, so I want to count the number of visible cells in
> Row 4.
> I use the following code to give me that count. I get an error on this
> line.
> The error message is "Unable to get the SpecialCells property of the range
> class."
> ColCount = Range("A4", Cells(4, Columns.Count).End(xlToLeft)) _
> .SpecialCells(xlCellTypeVisible).Count
> This seems simple to do. What am I doing wrong? Thanks for your time.
> Otto
>
>
>

 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      24th Nov 2006
Some more information.
This line of code is in a Workbook_BeforePrint macro.
There is only one sheet in the file.
I put that line of code, as follows, in a regular module in the same file
and it runs fine.
MsgBox Range("A4", Cells(4, Columns.Count).End(xlToLeft)) _
.SpecialCells(xlCellTypeVisible).Count
Then I took ALL the code from the Workbook module and put it into a regular
macro (with a different macro name) and it worked just fine.
The problem apparantly is because I have that code in a Workbook event
macro.
So there is something here that I have to learn. What happened? Thanks for
your time. Otto
"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:OkenrX$(E-Mail Removed)...
> Excel XP, Win XP
> Helping an OP.
> I have a range with numerous hidden columns.
> The hidden columns are not contiguous.
> Columns A:B are always visible.
> I want to count the number of visible columns.
> Row 4 is the header row, so I want to count the number of visible cells in
> Row 4.
> I use the following code to give me that count. I get an error on this
> line.
> The error message is "Unable to get the SpecialCells property of the range
> class."
> ColCount = Range("A4", Cells(4, Columns.Count).End(xlToLeft)) _
> .SpecialCells(xlCellTypeVisible).Count
> This seems simple to do. What am I doing wrong? Thanks for your time.
> Otto
>



 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      24th Nov 2006
All is well.
I changed the Workbook_BeforePrint macro code to:
Cancel = True
Call ThePrintMacro
'All the code went into the ThePrintMacro
Apparently there are some rules about what you can and can't put into a
Workbook_BeforePrint macro.
Does anybody know what the problem was? Thanks for your time. Otto
"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:OkenrX$(E-Mail Removed)...
> Excel XP, Win XP
> Helping an OP.
> I have a range with numerous hidden columns.
> The hidden columns are not contiguous.
> Columns A:B are always visible.
> I want to count the number of visible columns.
> Row 4 is the header row, so I want to count the number of visible cells in
> Row 4.
> I use the following code to give me that count. I get an error on this
> line.
> The error message is "Unable to get the SpecialCells property of the range
> class."
> ColCount = Range("A4", Cells(4, Columns.Count).End(xlToLeft)) _
> .SpecialCells(xlCellTypeVisible).Count
> This seems simple to do. What am I doing wrong? Thanks for your time.
> Otto
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Visible Cells and paste in another workbook visible cells only Abdul Microsoft Excel Programming 5 2nd Aug 2009 02:08 AM
Counting visible rows atledreier Microsoft Excel Programming 1 1st Aug 2007 01:02 PM
Selecting a cell based on counting visible cells from the top Alan Microsoft Excel Misc 1 26th Jun 2004 12:53 AM
Counting visible cells Otto Moehrbach Microsoft Excel Programming 1 18th Sep 2003 03:01 PM
Help: Copying Visible Cells only to Visible cells! Jay Jayakumar Microsoft Excel Programming 0 9th Jul 2003 08:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 PM.