LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Macro runtime 1004 error on opening worksheet

I have a macro (coding below) that autofilters a worksheet (AA) then removes
blanks, copies the data then pastes it on a seperate sheet (sheet2). This is
then used for a data validation list.
A long way round to get only nonblank values in a data validation list on a
seperate worksheet called Menu.

The code:

Sub AA()
'
' AA Macro
' Macro recorded 01/05/2009 by Shaggyjh
'

'
Sheets("AA").Visible = True
Sheets("Sheet2").Visible = True
Sheets("AA").Select
Range("A1:O100").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="<"
Range("A1:A101").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Sheets("AA").Visible = False
Sheets("Sheet2").Visible = False

End Sub

If i run this macro via the tools menu it works perfectly. However if i
open the view code on the Menu worksheet and enter the following code i get
an error!
The error is highlighting:

Range("A1:O100").Select

What am i doing wrong? Or is there a better way to do it? I want it to
automatically refresh the data validation list on the hidden sheet2 so that i
don't have to rely on users to click a button before using the drop down list!



Private Sub Worksheet_Activate()

'
' AA Macro
' Macro recorded 01/05/2009 by Shaggyjh
'

'
Sheets("AA").Visible = True
Sheets("Sheet2").Visible = True
Sheets("AA").Select
Range("A1:O100").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="<"
Range("A1:A101").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Sheets("AA").Visible = False
Sheets("Sheet2").Visible = False

End Sub






 
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
unable to protect cells in macro sheet b/c runtime error 1004 rldjda Excel Worksheet Functions 1 March 20th 08 08:28 PM
Macro runtime error 1004 with Autofilter Lorna B Excel Discussion (Misc queries) 3 May 25th 07 08:38 PM
Another runtime 1004 error [email protected] Excel Discussion (Misc queries) 2 September 17th 05 09:21 AM
Runtime Error '1004' [email protected] Excel Discussion (Misc queries) 2 July 18th 05 06:10 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


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

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"