PC Review


Reply
Thread Tools Rate Thread

Cells.find only reporting range in AutoFilter...

 
 
=?Utf-8?B?bWFyaw==?=
Guest
Posts: n/a
 
      24th Oct 2007
Years ago, someone here recommended that I use this to find the intersection
of the last used row and column, independant of whether data had been deleted
since the last save, etc:

reallastrow = Cells.Find("*", Range("A1"), xlFormulas, , xlByRows,
xlPrevious).Row
reallastcol = Cells.Find("*", Range("A1"), xlFormulas, , xlByColumns,
xlPrevious).Column

I've just discovered that the reallastcol part doesn't work if an AutoFilter
is turned on.

Instead of the last used column in the worksheet, it reports the last used
column in the autofilter, ignoring the fact that columns may be used to the
right of the autofilter.

Suggestions?


 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      25th Oct 2007

If objSheet.FilterMode Then objSheet.ShowAllData
--or--
If objSheet.FilterMode Then
MsgBox "Please turn off the auto filter"
Exit sub
End if
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"mark" <(E-Mail Removed)>
wrote in message
Years ago, someone here recommended that I use this to find the intersection
of the last used row and column, independant of whether data had been deleted
since the last save, etc:

reallastrow = Cells.Find("*", Range("A1"), xlFormulas, , xlByRows,
xlPrevious).Row
reallastcol = Cells.Find("*", Range("A1"), xlFormulas, , xlByColumns,
xlPrevious).Column

I've just discovered that the reallastcol part doesn't work if an AutoFilter
is turned on.
Instead of the last used column in the worksheet, it reports the last used
column in the autofilter, ignoring the fact that columns may be used to the
right of the autofilter.
Suggestions?


 
Reply With Quote
 
=?Utf-8?B?bWFyaw==?=
Guest
Posts: n/a
 
      25th Oct 2007
If my intent were to turn off the auto-filter, then sure, I could do that, no
problem.

But that's not my intent. I guess I didn't state the problem well enough.

After the operations that my code will perform, I still want the autofilter
to be on; in fact, having it on will cause my code to need to do less work.

So, I don't want to turn it off. I could turn it off, find the cell
intersection, and then turn it back on, but then I'd have to write in an
array to remember what all the selected filters in the auto filter were, and
I wasn't in a mood to bother with that today, either.

I think I can do it by a combination of the usedrange.columns.count , and
the position of the first column in the used range (since Excel doesn't count
blank columns on the left as part of the used range, if there is nothing in
them).



"Jim Cone" wrote:

>
> If objSheet.FilterMode Then objSheet.ShowAllData
> --or--
> If objSheet.FilterMode Then
> MsgBox "Please turn off the auto filter"
> Exit sub
> End if
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
>
>
>
> "mark" <(E-Mail Removed)>
> wrote in message
> Years ago, someone here recommended that I use this to find the intersection
> of the last used row and column, independant of whether data had been deleted
> since the last save, etc:
>
> reallastrow = Cells.Find("*", Range("A1"), xlFormulas, , xlByRows,
> xlPrevious).Row
> reallastcol = Cells.Find("*", Range("A1"), xlFormulas, , xlByColumns,
> xlPrevious).Column
>
> I've just discovered that the reallastcol part doesn't work if an AutoFilter
> is turned on.
> Instead of the last used column in the worksheet, it reports the last used
> column in the autofilter, ignoring the fact that columns may be used to the
> right of the autofilter.
> Suggestions?
>
>
>

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      28th Oct 2007

Sub GetLastCol()
MsgBox ReallyLastColumn
End Sub
'--
Function ReallyLastColumn()
Dim lngCol As Long
Dim N As Long
Dim lngRow As Long
With ActiveSheet.UsedRange
lngRow = .Rows(.Rows.Count).Row
End With
For N = 1 To lngRow
With ActiveSheet
lngCol = Application.Max(lngCol, .Cells(N, .Columns.Count).End(xlToLeft).Column)
End With
Next
ReallyLastColumn = lngCol
End Function
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"mark"
wrote in message
If my intent were to turn off the auto-filter, then sure, I could do that, no
problem.

But that's not my intent. I guess I didn't state the problem well enough.

After the operations that my code will perform, I still want the autofilter
to be on; in fact, having it on will cause my code to need to do less work.

So, I don't want to turn it off. I could turn it off, find the cell
intersection, and then turn it back on, but then I'd have to write in an
array to remember what all the selected filters in the auto filter were, and
I wasn't in a mood to bother with that today, either.

I think I can do it by a combination of the usedrange.columns.count , and
the position of the first column in the used range (since Excel doesn't count
blank columns on the left as part of the used range, if there is nothing in
them).
 
Reply With Quote
 
=?Utf-8?B?bWFyaw==?=
Guest
Posts: n/a
 
      30th Oct 2007
yeah, that would work. thanks for the suggestion...

see what you're doing...

1) finding the number of rows use
2) walking down the rows and finding the right-most used cell
3) keeping the max of that until you get through the number of rows used.

that would do it.

"Jim Cone" wrote:

>
> Sub GetLastCol()
> MsgBox ReallyLastColumn
> End Sub
> '--
> Function ReallyLastColumn()
> Dim lngCol As Long
> Dim N As Long
> Dim lngRow As Long
> With ActiveSheet.UsedRange
> lngRow = .Rows(.Rows.Count).Row
> End With
> For N = 1 To lngRow
> With ActiveSheet
> lngCol = Application.Max(lngCol, .Cells(N, .Columns.Count).End(xlToLeft).Column)
> End With
> Next
> ReallyLastColumn = lngCol
> End Function
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
>
>
>
>
> "mark"
> wrote in message
> If my intent were to turn off the auto-filter, then sure, I could do that, no
> problem.
>
> But that's not my intent. I guess I didn't state the problem well enough.
>
> After the operations that my code will perform, I still want the autofilter
> to be on; in fact, having it on will cause my code to need to do less work.
>
> So, I don't want to turn it off. I could turn it off, find the cell
> intersection, and then turn it back on, but then I'd have to write in an
> array to remember what all the selected filters in the auto filter were, and
> I wasn't in a mood to bother with that today, either.
>
> I think I can do it by a combination of the usedrange.columns.count , and
> the position of the first column in the used range (since Excel doesn't count
> blank columns on the left as part of the used range, if there is nothing in
> them).
>

 
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
Find Autofilter Header range David Microsoft Excel Programming 5 7th Oct 2009 01:34 PM
autofilter is hiding cells outisde of the range I am trying to fil =?Utf-8?B?ZHBvbGtpbmc=?= Microsoft Excel Misc 1 1st Oct 2007 08:31 PM
Error proof way to find first blank Row after Autofilter Range EagleOne@discussions.microsoft.com Microsoft Excel Programming 6 1st Jul 2007 01:42 AM
How do I find blank cells using AutoFilter's Custom feature? =?Utf-8?B?QW5kcmVhIEJsYWtl?= Microsoft Excel Worksheet Functions 2 30th Nov 2004 09:03 PM
AutoFilter.Range Visible Cells to Array? Dennis@NoSpam.com Microsoft Excel Misc 6 19th Nov 2003 06:38 PM


Features
 

Advertising
 

Newsgroups
 


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