Compile Error: Variable Not Defined?

dbdev

New Member
Joined
Apr 3, 2013
Messages
2
Hi,

I can't seem to get the functionality to work. I get a Compile Error: Variable not defined and "Sub GetSQLData2()" is highlighted whereas SQL2 is selected, can someone please help me. Thank you


Sub GetSQLData2()


Dim sql As String
Dim r As Range

OTW45.AutoFilterMode = False

OTW45.Range("DataDrop2").Offset(1, 0).Resize(65000, 200).ClearContents

sql = SQL2.TextBoxes("SQLTextBox2").Text
Set r = OTW45.Range("DataDrop2").Offset(1, 0)
LoadWorkSheet r, sql

OTW45.Range("OTW45Filt").AutoFilter


End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
What is OTW45 ?

dim OTW45 as worksheet

set OTW45 = worksheets("OTW45")

assuming it is a worksheet
 
Upvote 0
then you ned to add the 2 lines the dim and set statements below the dim r as range line in your code
 
Upvote 0

Forum statistics

Threads
1,203,242
Messages
6,054,350
Members
444,718
Latest member
r0nster

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