Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default SpecialCells(xlCellTypeVisible) driving me nuts


The following is the data in my spreadsheet

first second
jdjj jkkjk
sss sdd
sss fda
sa fdfd
hah klk

The following is the code I'm wrting to test it:

Sub test()

Dim r As Range

With Sheets("Sheet2")
.AutoFilterMode = False
.UsedRange.AutoFilter field:=1, Criteria1:="hah"
.UsedRange.AutoFilter field:=2, Criteria1:="klk"

Set r = .UsedRange.SpecialCells(xlCellTypeVisible)

.UsedRange.AutoFilter
End With

End Sub

Problem: Even though both the header and one row of data are clearly
visible, range "r" only ever returns the header row (r.rows.count is
always = 1 instead of 2) .

Any idea what might be causing this problem?

Rob

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default SpecialCells(xlCellTypeVisible) driving me nuts

Try this -

Dim r as Range, ar as Range

' code

For Each ar In r.Areas
With ar
Debug.Print .Rows.Count, .Address
End With
Next

Regards,
Peter T


"signon77" wrote in message
...

The following is the data in my spreadsheet

first second
jdjj jkkjk
sss sdd
sss fda
sa fdfd
hah klk

The following is the code I'm wrting to test it:

Sub test()

Dim r As Range

With Sheets("Sheet2")
.AutoFilterMode = False
.UsedRange.AutoFilter field:=1, Criteria1:="hah"
.UsedRange.AutoFilter field:=2, Criteria1:="klk"

Set r = .UsedRange.SpecialCells(xlCellTypeVisible)

.UsedRange.AutoFilter
End With

End Sub

Problem: Even though both the header and one row of data are clearly
visible, range "r" only ever returns the header row (r.rows.count is
always = 1 instead of 2) .

Any idea what might be causing this problem?

Rob



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SpecialCells(xlCellTypeVisible) driving me nuts


r.rows.count only counts the rows in the first area of r.

Try

Code:
--------------------
Sub test()
Dim r As Range
Dim nRow As Long

With Sheets("Sheet2")
.AutoFilterMode = False
.UsedRange.AutoFilter field:=1, Criteria1:="hah"
.UsedRange.AutoFilter field:=2, Criteria1:="klk"

Set r = .UsedRange.SpecialCells(xlCellTypeVisible)

.UsedRange.AutoFilter
nRow = Intersect(r(1).EntireColumn, r).Count
MsgBox "nRow = " & nRow
End With
End Sub
--------------------


--
shg
------------------------------------------------------------------------
shg's Profile: http://www.thecodecage.com/forumz/member.php?userid=13
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=27214

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default SpecialCells(xlCellTypeVisible) driving me nuts

See what you get if you use:

Set r = ActiveSheet.Cells.SpecialCells(xlCellTypeVisible)

"signon77" wrote:


The following is the data in my spreadsheet

first second
jdjj jkkjk
sss sdd
sss fda
sa fdfd
hah klk

The following is the code I'm wrting to test it:

Sub test()

Dim r As Range

With Sheets("Sheet2")
.AutoFilterMode = False
.UsedRange.AutoFilter field:=1, Criteria1:="hah"
.UsedRange.AutoFilter field:=2, Criteria1:="klk"

Set r = .UsedRange.SpecialCells(xlCellTypeVisible)

.UsedRange.AutoFilter
End With

End Sub

Problem: Even though both the header and one row of data are clearly
visible, range "r" only ever returns the header row (r.rows.count is
always = 1 instead of 2) .

Any idea what might be causing this problem?

Rob


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SpecialCells(xlCellTypeVisible) driving me nuts

Check your other thread, too.

signon77 wrote:

The following is the data in my spreadsheet

first second
jdjj jkkjk
sss sdd
sss fda
sa fdfd
hah klk

The following is the code I'm wrting to test it:

Sub test()

Dim r As Range

With Sheets("Sheet2")
.AutoFilterMode = False
.UsedRange.AutoFilter field:=1, Criteria1:="hah"
.UsedRange.AutoFilter field:=2, Criteria1:="klk"

Set r = .UsedRange.SpecialCells(xlCellTypeVisible)

.UsedRange.AutoFilter
End With

End Sub

Problem: Even though both the header and one row of data are clearly
visible, range "r" only ever returns the header row (r.rows.count is
always = 1 instead of 2) .

Any idea what might be causing this problem?

Rob


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default SpecialCells(xlCellTypeVisible) driving me nuts

On Nov 9, 6:06*pm, Dave Peterson wrote:
Check your other thread, too.





signon77 wrote:

The following is the data in my spreadsheet


first * second
jdjj * *jkkjk
sss * * sdd
sss * * fda
sa * * *fdfd
hah * * klk


The following is the code I'm wrting to test it:


Sub test()


Dim r As Range


With Sheets("Sheet2")
* .AutoFilterMode = False
* .UsedRange.AutoFilter field:=1, Criteria1:="hah"
* .UsedRange.AutoFilter field:=2, Criteria1:="klk"


* Set r = .UsedRange.SpecialCells(xlCellTypeVisible)


* * .UsedRange.AutoFilter
*End With


End Sub


Problem: Even though both the header and one row of data are clearly
visible, range "r" only ever returns the header row (r.rows.count is
always = 1 instead of 2) .


Any idea what might be causing this problem?


Rob


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Guys,

What can I say but thank you?

Who would have thought that range: "r" actually had multiple ranges
known as areas. This painful learning experience has been worth it. I
work at an investment bank in London supporting Middle Office
spreadsheets. Some of them are so bad and slow I silently despair. You
guys helping me like this means I don't have to write a relatively
slow "for loop" to get round the issue.

Thanks again,

Rob
Reply
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
using UsedRange.SpecialCells(xlCellTypeVisible).Areas(2) TD Excel Programming 4 February 23rd 07 02:18 PM
Need Help, this is driving me nuts heitorfjr Excel Discussion (Misc queries) 2 January 15th 06 03:10 PM
activecell.specialcells(xlCellTypeVisible) returns column refe noel Excel Programming 1 January 4th 05 04:33 PM
Excel / VB is driving me nuts!! Andrew Excel Worksheet Functions 2 November 29th 04 04:06 AM
Worksheet function & SpecialCells(xlCellTypeVisible)? Charley Kyd[_2_] Excel Programming 2 March 5th 04 05:46 PM


All times are GMT +1. The time now is 01:10 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"