Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoFilter in Excel Workbook

Status
Not open for further replies.

jennuhw

MIS
Apr 18, 2001
426
US
I am trying to set the autofilter up for each sheet of my workbook if there is any information on them. For some reason, no matter how I code it, the last sheet to get the autofilter applied is the only one that has the autofilter on. Any ideas?

Below is my code shortened up:

Code:
Set objXlApp = Server.CreateObject("Excel.Application")

objxlapp.visible = true

' open the spreadsheet file
set books = objXlApp.Workbooks.open(fname) 

' get the worksheet
Set objXlSheets = books.Worksheets(1)

''bunches of code

if isarray(query1) then
	for y = 0 to ubound(query1,2)
		
		'filling a bunch of cells with values

		x = x + 1
	next
	objxlsheets.range("A:L").autofilter
else
	objxlsheets.range("A2").value = "No results found."
end if 

' get the worksheet
Set objXlSheets = books.Worksheets(2)

''bunches of code

if isarray(query2) then
	for y = 0 to ubound(query2,2)
		
		'filling a bunch of cells with values

		x = x + 1
	next
	objxlsheets.range("A:L").autofilter
else
	objxlsheets.range("A2").value = "No results found."
end if

I have tried to replace this line:
objxlsheets.range("A:L").autofilter
with:
books.Worksheets(x).range("A:L").autofilter ' x represents the sheet number
but it never ever works!
Thanks!
 
Figured it out. I had a typo of using the activesheet in one of my other sections. Oops!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top