VBA Auto Filter on Server Connection

Radison32

New Member
Joined
Oct 10, 2016
Messages
3
Hi All

I have created a VBA for filtering a table of values (see below) which works great, the reference used to filter the table is coming from another tab on the sheet.
When i try and apply the same type of VBA filter on data table on another tab which is a connection to a SQL server it fails
saying "Data-time error 1004".


Sub Filter()

With Sheets("Sheet2")

.Range("A2:H9").AutoFilter Field:=5, Criteria1:=Worksheets("Sheet3").Range("B2").Value
.Range("A2:H9").AutoFilter Field:=6, Criteria1:=Worksheets("Sheet3").Range("C2").Value


End With




End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi All

School boy error I selected more in the range than was being returned from the server.
An easy solution to my problem was to create a range that will grow as the results grow.

Sub Filter()

With Sheets("Sheet2")

Lastrow = ThisWorkbook.Sheets("Sheet2").Cells(2, 1).End(xlDown).Row
.Range("A2:A" & Lastrow).AutoFilter Field:=5, Criteria1:=Worksheets("Sheet3").Range("B2").Value

End With

End Sub

Thanks to anyone that looked in to this for me.
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top