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

With apologies as I first posted this to Printing.

I am trying to trap the first available non costed date and the last in the
simplified table below.
But instead of:
firstdate = 01 Feb 2007 and lastdate = 03 Mar 2007 the code returns
firstdate = 01 Feb 2007 and lastdate also = 01 Feb 2007

For Each cell In vistbl
Debug.Print cell.Value & vbTab & cell.Row
Next
Returns:
01/02/2007 2
2
03/03/2007 4
4

Can someone please correct me?

T.I.A.

Geoff

Column A Column B
Date Cost
01 Feb 2007
03 Feb 2007 34.62
03 Mar 2007
04 Mar 2007 50.00

Sub GetCostDates()

Dim tbl As Range, vistbl As Range, cell As Range
Dim firstdate As Date, lastdate As Date

With Sheets(1)

Set vistbl = Nothing
Set tbl = .Range("A2").CurrentRegion
.Range("A2").AutoFilter Field:=2, Criteria1:="=" '''filter out
non-blanks
Set tbl = tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1)

On Error Resume Next
Set vistbl = tbl.SpecialCells(xlVisible)
On Error GoTo 0

If Not vistbl Is Nothing Then
firstdate = .Cells(vistbl.Rows(1).Row, 1)
lastdate = .Cells(vistbl.Rows(vistbl.Rows.Count).Row, 1)
Else
firstdate = 0
lastdate = 0
End If

.Range("A2").AutoFilter

End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default SpecialCells(xlVisible)

The range is broken into areas

Option Explicit

Sub GetCostDates()

Dim tbl As Range, vistbl As Range, cell As Range
Dim firstdate As Date, lastdate As Date
Dim i As Long

With Sheets(3)

Set vistbl = Nothing
Set tbl = .Range("A2").CurrentRegion
.Range("A2").AutoFilter Field:=2, Criteria1:="=" '''filter out
non -blanks
Set tbl = tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1)

On Error Resume Next
Set vistbl = tbl.SpecialCells(xlVisible)
On Error GoTo 0

If Not vistbl Is Nothing Then
i = vistbl.Areas.Count
firstdate = .Cells(vistbl.Areas(1).Rows(1).Row, 1)
lastdate =
..Cells(vistbl.Areas(i).Rows(vistbl.Areas(i).Rows. Count).Row, 1)
Else
firstdate = 0
lastdate = 0
End If

.Range("A2").AutoFilter

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Geoff" wrote in message
...
With apologies as I first posted this to Printing.

I am trying to trap the first available non costed date and the last in
the
simplified table below.
But instead of:
firstdate = 01 Feb 2007 and lastdate = 03 Mar 2007 the code returns
firstdate = 01 Feb 2007 and lastdate also = 01 Feb 2007

For Each cell In vistbl
Debug.Print cell.Value & vbTab & cell.Row
Next
Returns:
01/02/2007 2
2
03/03/2007 4
4

Can someone please correct me?

T.I.A.

Geoff

Column A Column B
Date Cost
01 Feb 2007
03 Feb 2007 34.62
03 Mar 2007
04 Mar 2007 50.00

Sub GetCostDates()

Dim tbl As Range, vistbl As Range, cell As Range
Dim firstdate As Date, lastdate As Date

With Sheets(1)

Set vistbl = Nothing
Set tbl = .Range("A2").CurrentRegion
.Range("A2").AutoFilter Field:=2, Criteria1:="=" '''filter out
non-blanks
Set tbl = tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1)

On Error Resume Next
Set vistbl = tbl.SpecialCells(xlVisible)
On Error GoTo 0

If Not vistbl Is Nothing Then
firstdate = .Cells(vistbl.Rows(1).Row, 1)
lastdate = .Cells(vistbl.Rows(vistbl.Rows.Count).Row, 1)
Else
firstdate = 0
lastdate = 0
End If

.Range("A2").AutoFilter

End With

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default SpecialCells(xlVisible)

Thank you - I could see the visible cells were in separate areas using the
simple technique of copying the ranges and seeing the marquee (?) But I
hadn't thought to use Areas to enumerate through them.

Thanks again.

Geoff

"Bob Phillips" wrote:

The range is broken into areas

Option Explicit

Sub GetCostDates()

Dim tbl As Range, vistbl As Range, cell As Range
Dim firstdate As Date, lastdate As Date
Dim i As Long

With Sheets(3)

Set vistbl = Nothing
Set tbl = .Range("A2").CurrentRegion
.Range("A2").AutoFilter Field:=2, Criteria1:="=" '''filter out
non -blanks
Set tbl = tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1)

On Error Resume Next
Set vistbl = tbl.SpecialCells(xlVisible)
On Error GoTo 0

If Not vistbl Is Nothing Then
i = vistbl.Areas.Count
firstdate = .Cells(vistbl.Areas(1).Rows(1).Row, 1)
lastdate =
..Cells(vistbl.Areas(i).Rows(vistbl.Areas(i).Rows. Count).Row, 1)
Else
firstdate = 0
lastdate = 0
End If

.Range("A2").AutoFilter

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Geoff" wrote in message
...
With apologies as I first posted this to Printing.

I am trying to trap the first available non costed date and the last in
the
simplified table below.
But instead of:
firstdate = 01 Feb 2007 and lastdate = 03 Mar 2007 the code returns
firstdate = 01 Feb 2007 and lastdate also = 01 Feb 2007

For Each cell In vistbl
Debug.Print cell.Value & vbTab & cell.Row
Next
Returns:
01/02/2007 2
2
03/03/2007 4
4

Can someone please correct me?

T.I.A.

Geoff

Column A Column B
Date Cost
01 Feb 2007
03 Feb 2007 34.62
03 Mar 2007
04 Mar 2007 50.00

Sub GetCostDates()

Dim tbl As Range, vistbl As Range, cell As Range
Dim firstdate As Date, lastdate As Date

With Sheets(1)

Set vistbl = Nothing
Set tbl = .Range("A2").CurrentRegion
.Range("A2").AutoFilter Field:=2, Criteria1:="=" '''filter out
non-blanks
Set tbl = tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1)

On Error Resume Next
Set vistbl = tbl.SpecialCells(xlVisible)
On Error GoTo 0

If Not vistbl Is Nothing Then
firstdate = .Cells(vistbl.Rows(1).Row, 1)
lastdate = .Cells(vistbl.Rows(vistbl.Rows.Count).Row, 1)
Else
firstdate = 0
lastdate = 0
End If

.Range("A2").AutoFilter

End With

End Sub




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
SpecialCells Value=0?? Otto Moehrbach Excel Programming 2 December 9th 06 02:23 PM
SpecialCells help Graham Y Excel Programming 2 October 11th 06 05:16 PM
SpecialCells Peter Excel Programming 3 April 12th 06 02:03 PM
Autofilter/xlVisible problem when counting rows johli Excel Programming 6 September 27th 05 09:24 AM
Excel03 - empty cells and SpecialCells ( xlVisible ) Chris Paterson Excel Programming 2 August 23rd 05 02:35 PM


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

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

About Us

"It's about Microsoft Excel"