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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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