Hi,
I am trying to stop the designated ranges from auto-refreshing in the original VBA code. Whenever you put something in the highlighted ranges it auto-refreshes the file. Thanks for your help!
Here is what the current range is and also the SQL query has been hidden.
Imgur: The most awesome images on the Internet
I am trying to stop the designated ranges from auto-refreshing in the original VBA code. Whenever you put something in the highlighted ranges it auto-refreshes the file. Thanks for your help!
Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Not Intersect(Target, Range("C3:C6")) Is Nothing Then
Dim sql As String
Dim pn As String
Dim loc As String
Dim line As String
Dim strsql As String
Dim endsql As String
Dim pnsql As String
Dim locsql As String
Dim sdt As String
Dim midsql As String
Dim sdtgdate As String
Dim sdtfdate As String
pn = Range("C3").Value
loc = Range("C4").Value
line = Range("C5").Value
sdt = Range("C6").Value
strsql = " select Stuff "
midsql = " Stuff "
endsql = " Stuff "
trueendsql = " Stuff "
If pn = "" Then pnsql = "" Else pnsql = " and i.invtid like '" + pn + "%'"
If loc = "" Then locsql = "" Else locsql = " and l.whseloc like '" + loc + "%'"
If line = "" Then linesql = "" Else linesql = " and i.classid like '" + line + "%'"
If sdt = "" Then sdtfdate = "" Else sdtfdate = "where promdate<getdate()+" + sdt + ""
If sdt = "" Then sdtgdate = "" Else sdtgdate = "and trandate>getdate()-" + sdt + ""
sql = strsql + sdtfdate + midsql + sdtgdate + endsql + pnsql + locsql + linesql + trueendsql
Range("A8").Select
With Selection.QueryTable
.Connection = Array( _
"OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Business;Data Source=dbs02\sqle" _
, _
"xpress;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=OXN-WKSR5H;Use Encryption for Data=False;" _
, "Tag with column collation when possible=False")
.CommandType = xlCmdSql
.CommandText = sql
.Refresh BackgroundQuery:=False
End With
Else
End If
Range("C3").Select
End Sub
Here is what the current range is and also the SQL query has been hidden.
Imgur: The most awesome images on the Internet