PC Review


Reply
Thread Tools Rate Thread

Changing string input in a query within a macro

 
 
=?Utf-8?B?bXNkcm9sZg==?=
Guest
Posts: n/a
 
      16th Oct 2006
I have created a query with the macro recorder in Excel 2003. During the
creation process a string input is required. I would now like to pull the
string input from a cell reference from another sheet in the workbook. Here
is the key part of the query/macro:

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=Excel
Files;DBQ=C:\Data\Macro\MacroData.xls;DefaultDir=C:\Data\Macro;DriverId=790;MaxBufferSize=2048;PageTimeout=5;" _
, Destination:=Range("G15"))
.CommandText = Array( _
"SELECT REGION.REGION, REGION.Name, REGION.CUSTNO, REGION.SALES" &
Chr(13) & "" & Chr(10) & "FROM `C:\Data\Macro\MacroData`.REGION REGION" &
Chr(13) & "" & Chr(10) & "WHERE (REGION.Name='DANIEL')" & Chr(13) & "" &
Chr(10) & "ORDER BY REGION.CUSTNO" _
)

In the WHERE command I want to change the string DANIEL to the input from
cell C3 in the INPUT sheet. I need to to do this about 200 times and just
want to change the name and have the macro do the rest. Is this possible.
Thanks.
 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      17th Oct 2006
"WHERE (REGION.Name='DANIEL')"

becomes

"WHERE (REGION.Name='" & worksheets("Input").Range("C3").Value & "')"

--
Regards,
Tom Ogilvy

"msdrolf" <(E-Mail Removed)> wrote in message
news:8C3B609D-2E7D-44FE-9FBC-(E-Mail Removed)...
>I have created a query with the macro recorder in Excel 2003. During the
> creation process a string input is required. I would now like to pull the
> string input from a cell reference from another sheet in the workbook.
> Here
> is the key part of the query/macro:
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "ODBC;DSN=Excel
> Files;DBQ=C:\Data\Macro\MacroData.xls;DefaultDir=C:\Data\Macro;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
> _
> , Destination:=Range("G15"))
> .CommandText = Array( _
> "SELECT REGION.REGION, REGION.Name, REGION.CUSTNO, REGION.SALES" &
> Chr(13) & "" & Chr(10) & "FROM `C:\Data\Macro\MacroData`.REGION REGION" &
> Chr(13) & "" & Chr(10) & "WHERE (REGION.Name='DANIEL')" & Chr(13) & "" &
> Chr(10) & "ORDER BY REGION.CUSTNO" _
> )
>
> In the WHERE command I want to change the string DANIEL to the input from
> cell C3 in the INPUT sheet. I need to to do this about 200 times and just
> want to change the name and have the macro do the rest. Is this possible.
> Thanks.



 
Reply With Quote
 
=?Utf-8?B?bXNkcm9sZg==?=
Guest
Posts: n/a
 
      17th Oct 2006
Many thanks - your suggestion works beautifully.

"Tom Ogilvy" wrote:

> "WHERE (REGION.Name='DANIEL')"
>
> becomes
>
> "WHERE (REGION.Name='" & worksheets("Input").Range("C3").Value & "')"
>
> --
> Regards,
> Tom Ogilvy
>
> "msdrolf" <(E-Mail Removed)> wrote in message
> news:8C3B609D-2E7D-44FE-9FBC-(E-Mail Removed)...
> >I have created a query with the macro recorder in Excel 2003. During the
> > creation process a string input is required. I would now like to pull the
> > string input from a cell reference from another sheet in the workbook.
> > Here
> > is the key part of the query/macro:
> >
> > With ActiveSheet.QueryTables.Add(Connection:= _
> > "ODBC;DSN=Excel
> > Files;DBQ=C:\Data\Macro\MacroData.xls;DefaultDir=C:\Data\Macro;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
> > _
> > , Destination:=Range("G15"))
> > .CommandText = Array( _
> > "SELECT REGION.REGION, REGION.Name, REGION.CUSTNO, REGION.SALES" &
> > Chr(13) & "" & Chr(10) & "FROM `C:\Data\Macro\MacroData`.REGION REGION" &
> > Chr(13) & "" & Chr(10) & "WHERE (REGION.Name='DANIEL')" & Chr(13) & "" &
> > Chr(10) & "ORDER BY REGION.CUSTNO" _
> > )
> >
> > In the WHERE command I want to change the string DANIEL to the input from
> > cell C3 in the INPUT sheet. I need to to do this about 200 times and just
> > want to change the name and have the macro do the rest. Is this possible.
> > Thanks.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing constants in a query to user input values PamB Microsoft Access Queries 2 4th Jun 2010 05:52 AM
Macro for changing the colors of objects based on user input sara Microsoft Powerpoint 2 6th Oct 2008 04:10 PM
Macro to edit text string data input =?Utf-8?B?RGVl?= Microsoft Excel Programming 5 29th Nov 2005 04:52 AM
Query skips input for Where clause if second table or query added or if prompt contains blanks in the prompt string =?Utf-8?B?SHVudGVy?= Microsoft Access Queries 0 18th Mar 2004 10:01 PM
vba substitution operator/ changing query string Adam Gotch Microsoft Access Macros 0 2nd Oct 2003 07:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:23 AM.