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:
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!
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!