Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

I've the following problem. When the the below code runs i get
"Autofilter method of range class failed". It says the problem is wit
the last line of code. The strange thing is that it even filters th
selected range, but it still has a problem with it.


If frmECR.cboVendor.Text = "PG&E" Then
Sheets("PG&E").Range("ListPGE").AutoFilter _
Field:=1, _
Criteria1:=frmECR.cboAccountNumber

This thing is driving me nuts. Any help you guys can give would b
appreciated.

Thanks

Jame

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

Hi,

did you try

Sheets("PG&E").Range("ListPGE").AutoFilter 1, frmECR.cboAccountNumbe

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

I still get the error even using that

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

hmmm...

I would define a Range object and set it manually.
Like this :

Dim r as Range
...

set r = Sheets("PG&E").Range("A1:B5") 'the address of the table

r.AutoFilter 1, frmECR.cboAccountNumber


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

it still doesn't work. Talk about frustrating huh. This thing is killin
me

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Autofilter nightmare

Try

If frmECR.cboVendor.Text = "PG&E" Then
Sheets("PG&E").Range("ListPGE").AutoFilter _
Field:=1, _
Criteria1:=frmECR.cboAccountNumber.Text


--
Regards,
Tom Ogilvy

Jmbostock wrote in message
...
I've the following problem. When the the below code runs i get a
"Autofilter method of range class failed". It says the problem is with
the last line of code. The strange thing is that it even filters the
selected range, but it still has a problem with it.


If frmECR.cboVendor.Text = "PG&E" Then
Sheets("PG&E").Range("ListPGE").AutoFilter _
Field:=1, _
Criteria1:=frmECR.cboAccountNumber

This thing is driving me nuts. Any help you guys can give would be
appreciated.

Thanks

James


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Autofilter nightmare

This worked fine for me:

Private Sub CommandButton1_Click()
If frmECR.cboVendor.Text = "PG&E" Then
Sheets("PG&E").Range("ListPGE").AutoFilter _
Field:=1, _
Criteria1:=frmECR.cboAccountNumber.Text
End If
End Sub


Private Sub UserForm_Initialize()
cboVendor.AddItem "ABC"
cboVendor.AddItem "EF&G"
cboVendor.AddItem "PG&E"
cboVendor.AddItem "MN&O"
cboAccountNumber.AddItem 1
cboAccountNumber.AddItem 2
cboAccountNumber.AddItem 3
End Sub


The range ListPGE was located on sheet PG&E

--
Regards,
Tom Ogilvy

Tom Ogilvy wrote in message
...
Try

If frmECR.cboVendor.Text = "PG&E" Then
Sheets("PG&E").Range("ListPGE").AutoFilter _
Field:=1, _
Criteria1:=frmECR.cboAccountNumber.Text


--
Regards,
Tom Ogilvy

Jmbostock wrote in message
...
I've the following problem. When the the below code runs i get a
"Autofilter method of range class failed". It says the problem is with
the last line of code. The strange thing is that it even filters the
selected range, but it still has a problem with it.


If frmECR.cboVendor.Text = "PG&E" Then
Sheets("PG&E").Range("ListPGE").AutoFilter _
Field:=1, _
Criteria1:=frmECR.cboAccountNumber

This thing is driving me nuts. Any help you guys can give would be
appreciated.

Thanks

James


---
Message posted from http://www.ExcelForum.com/





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

Still doesn't work. I cut the code down to the bare minimun just in case
something was effecting it that i didn't count on.

The userform initializes Then I click on the cbovendor and select one
of three items from a list, one of them being "PG&E".


Private Sub cboVendor_Change()
If frmECR.cboVendor.Text = "PG&E" Then
frmECR.cboAccountNumber.RowSource = "PGEAccount"
End If
End Sub

I then click on the cboAccountnumber, where it gives me a list of
account numbers. I select an account number and the following code
runs.

Private Sub cboAccountNumber_Change()
Sheets("PG&E").Select
Range("ListPGE").Select
Selection.AutoFilter Field:=1,
Criteria1:=frmECR.cboAccountNumber.Text
End Sub

This isn't the code it was previously, i instead recorded a macro and
copied it it, but it still didn't work.

any ideas???


---
Message posted from http://www.ExcelForum.com/

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Autofilter nightmare

You need a line continuation character in the filter command:

Private Sub cboAccountNumber_Change()
Sheets("PG&E").Select
Range("ListPGE").Select
Selection.AutoFilter Field:=1, _
Criteria1:=frmECR.cboAccountNumber.Text
End Sub

either that or put it all on one line.

--
Regards,
Tom Ogilvy


Jmbostock wrote in message
...
Still doesn't work. I cut the code down to the bare minimun just in case
something was effecting it that i didn't count on.

The userform initializes Then I click on the cbovendor and select one
of three items from a list, one of them being "PG&E".


Private Sub cboVendor_Change()
If frmECR.cboVendor.Text = "PG&E" Then
frmECR.cboAccountNumber.RowSource = "PGEAccount"
End If
End Sub

I then click on the cboAccountnumber, where it gives me a list of
account numbers. I select an account number and the following code
runs.

Private Sub cboAccountNumber_Change()
Sheets("PG&E").Select
Range("ListPGE").Select
Selection.AutoFilter Field:=1,
Criteria1:=frmECR.cboAccountNumber.Text
End Sub

This isn't the code it was previously, i instead recorded a macro and
copied it it, but it still didn't work.

any ideas???


---
Message posted from http://www.ExcelForum.com/



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

Even when i use the line continuation, or all on one line, it stil
gives me that Autofilter method range class error.

This thing is unbelievable.

i've no idea what's wrong with it

--
Message posted from http://www.ExcelForum.com



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Autofilter nightmare

is the sheet protected?

If you enter ListPGE in the name box and hit enter (ListPGE should be
selected) can you then do Data=filter=Autofilter and select an account
number in the first dropdown.

It has to be something particular to your environment. Applying an
autofilter really isn't that hard (any merged cells or anything else
unusual)?

--
Regards,
Tom Ogilvy

Jmbostock wrote in message
...
Even when i use the line continuation, or all on one line, it still
gives me that Autofilter method range class error.

This thing is unbelievable.

i've no idea what's wrong with it.


---
Message posted from http://www.ExcelForum.com/



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Autofilter nightmare

Thanks for everyones help, but i'm calling it quits on this particular
project.

I think the problem is related to something in the sheets, rather than
something i've written.

I'm going to start from scratch and hope for the best.

Again, you guys are awesome.

James


---
Message posted from http://www.ExcelForum.com/

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
Formula Nightmare IF function incompetent Excel Worksheet Functions 6 February 12th 08 05:54 PM
PivotTable Nightmare Sandi Excel Discussion (Misc queries) 3 March 3rd 07 04:34 PM
PivotTable Nightmare MarkM Excel Discussion (Misc queries) 1 August 14th 06 07:41 PM
IF Statement nightmare eugenevr Excel Discussion (Misc queries) 6 May 18th 05 01:09 PM
Protection nightmare Joe Bannister Excel Programming 1 January 27th 04 05:15 PM


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