Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Error 1004 on Range.Text with AutoFilter

I have a spreadsheet like this

A B C
----------------------------------------------------
2 | 1 123.4586 =my_func(B2)
3 | 2 2123.53132 =my_func(B3)
4 | 1 78231.74853 =my_func(B4)



Public Function my_func(tar As Range) As String
On Error GoTo handler

my_func = tar.Text

Exit Function
handler:
Debug.Print Err.Number
End Function

Sub test()
With Range("$A$2:$A$4")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="1"
End With
End Sub


Every time I run test() error code 1004 - Unable to get the Text
property of the Range class occurs. This error does not occur if I do
the autofilter manually.
Is there any workaround? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Error 1004 on Range.Text with AutoFilter

Your code should include a 'top' cell for the filter arrow and should be all one line...

Range("$A$1:$A$4").AutoFilter Field:=1, Criteria1:="1"
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
(Permutations Add-in: with option to highlight valid words)



"Edmond Lai"
wrote in message
...
I have a spreadsheet like this

A B C
----------------------------------------------------
2 | 1 123.4586 =my_func(B2)
3 | 2 2123.53132 =my_func(B3)
4 | 1 78231.74853 =my_func(B4)



Public Function my_func(tar As Range) As String
On Error GoTo handler

my_func = tar.Text

Exit Function
handler:
Debug.Print Err.Number
End Function

Sub test()
With Range("$A$2:$A$4")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="1"
End With
End Sub


Every time I run test() error code 1004 - Unable to get the Text
property of the Range class occurs. This error does not occur if I do
the autofilter manually.
Is there any workaround? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Error 1004 on Range.Text with AutoFilter

Hi Jim,

I tried your code but got the same result.


On Jul 17, 7:25*pm, "Jim Cone" wrote:
Your code should include a 'top' cell for the filter arrow and should be all one line...

* Range("$A$1:$A$4").AutoFilter Field:=1, Criteria1:="1"
--
Jim Cone
Portland, Oregon USAhttp://www.mediafire.com/PrimitiveSoftware
(Permutations Add-in: *with option to highlight valid words)

"Edmond Lai"
wrote in ...







I have a spreadsheet like this


* * A B C
----------------------------------------------------
2 | *1 123.4586 =my_func(B2)
3 | *2 2123.53132 =my_func(B3)
4 | *1 78231.74853 =my_func(B4)


Public Function my_func(tar As Range) As String
* *On Error GoTo handler


* *my_func = tar.Text


* *Exit Function
handler:
* *Debug.Print Err.Number
End Function


Sub test()
* *With Range("$A$2:$A$4")
* * * *.AutoFilter
* * * *.AutoFilter Field:=1, Criteria1:="1"
* *End With
End Sub


Every time I run test() error code 1004 - Unable to get the Text
property of the Range class occurs. This error does not occur if I do
the autofilter manually.
Is there any workaround? *Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Error 1004 on Range.Text with AutoFilter

Jim's code works for me as follows...

Sub FilterRange()
Range("$A$1:$A$4").AutoFilter Field:=1, Criteria1:="1"
Application.Calculate '**rebuild formulas**
End Sub

**Required to mitigate AutoFilter causing '#VALUE!' error (#1004)**

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
autofilter raises error 1004 chfa Excel Programming 8 November 4th 09 05:57 PM
Macro runtime error 1004 with Autofilter Lorna B Excel Discussion (Misc queries) 3 May 25th 07 08:38 PM
Mysterious Error 1004 caused by AutoFilter? Ken Johnson Excel Programming 5 March 5th 06 08:01 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Error 1004 update autofilter and pivottable fonz Excel Programming 1 October 12th 04 02:59 PM


All times are GMT +1. The time now is 10:33 PM.

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"