Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default excel build query from cells

Of course this is possible, but I need to know how you want it to work. For
example:

Lets add a parameter to your function definition:

Sub Sales_Query(rangTarget as range)

So later on you can use:

salesrep = rangTarget .Text
salesdate = rangTarget .offset(1,0).Value

....

Destination:=rangTarget .offset(3,-1)

....

There are a lot of other possibilities & considerations, how to pass
rngTarget to this procedure, what if you are in column A (the offset(3,-1)
would be illegal) etc.

However I hope this give you some food for thought and you will come back
with further info/clarification.





"jimmygoogle" wrote:

i have a spreadsheet where there is a field call it 'name' and when
the user types in the name it returns the result matching the where
clause - is it possible that i do not have to hardcode the cell number
so the user can enter and return as many result sets as they want

i dont have VB experience but i have programming experience so i was
hoping to follow this model i found but I would like to not have to
hardcode C2, C3, etc - i dont know if this is even possible - any
insight is appreciated

Sub Sales_Query()
Dim salesrep As Variant
Dim salesdate As Date

salesrep = Range("C2").Text
salesdate = Range("C3").Value
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"ODBC;DSN=Northwind;Description=Northwind;APP=Micr osoft Office
XP;DATABASE=Northwind;Trusted_Connection=YES"),
Destination:=Range("B5"))
.CommandText = Array("SELECT * FROM Orders WHERE EmployeeID="
& salesrep & " AND OrderDate '" & salesdate & "' ORDER BY
OrderDate")
.Name = "Sales Query from Northwind"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel build query from cells

On Jun 5, 2:46 am, Ben McBen
wrote:
Of course this is possible, but I need to know how you want it to work. For
example:

Lets add a parameter to your function definition:

Sub Sales_Query(rangTarget as range)

So later on you can use:

salesrep = rangTarget .Text
salesdate = rangTarget .offset(1,0).Value

...

Destination:=rangTarget .offset(3,-1)

...

There are a lot of other possibilities & considerations, how to pass
rngTarget to this procedure, what if you are in column A (the offset(3,-1)
would be illegal) etc.

However I hope this give you some food for thought and you will come back
with further info/clarification.

"jimmygoogle" wrote:
i have a spreadsheet where there is a field call it 'name' and when
the user types in the name it returns the result matching the where
clause - is it possible that i do not have to hardcode the cell number
so the user can enter and return as many result sets as they want


i dont have VB experience but i have programming experience so i was
hoping to follow this model i found but I would like to not have to
hardcode C2, C3, etc - i dont know if this is even possible - any
insight is appreciated


Sub Sales_Query()
Dim salesrep As Variant
Dim salesdate As Date


salesrep = Range("C2").Text
salesdate = Range("C3").Value
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"ODBC;DSN=Northwind;Description=Northwind;APP=Micr osoft Office
XP;DATABASE=Northwind;Trusted_Connection=YES"),
Destination:=Range("B5"))
.CommandText = Array("SELECT * FROM Orders WHERE EmployeeID="
& salesrep & " AND OrderDate '" & salesdate & "' ORDER BY
OrderDate")
.Name = "SalesQueryfrom Northwind"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



I guess salesrep I would want starting in column A2 and salesdate in
B2 with the results starting in D2
and have is be possible the user could enter stuff in A4,B4 then
A6,B6, etc (every other one). Does this help?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Build a query from a web-based database or a PDF file. Damian Excel Discussion (Misc queries) 0 October 26th 09 01:53 PM
How do I build an excel query? (something like SQL) tonyhabayeb Excel Programming 4 June 30th 06 04:24 PM
Using text in cells to build a link to within another file Jon Excel Discussion (Misc queries) 2 August 2nd 05 09:24 PM
Build lists with non contiguous cells [email protected] Excel Programming 1 April 11th 05 05:45 PM
How to build build a macro that automatically imports PedroPeso Excel Programming 1 December 26th 03 08:14 PM


All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"