Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2007, 06:59 AM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help

I got this very helpful answer:

Sub Dynamic_Query()

Dim sTabName As String
Dim sXS As String
Dim sQuery As String

sXS = CStr(Format(Date, "mmddyy"))
sTabName = "[" & sXS & "$]"
sQuery = "Select * From " & sTabName & ";" '

End Sub




to this post:

2 Posts

Posted - 07/31/2007 : 7:54:19 PM Show Profile Edit Topic Reply with Quote Report Abuse
I am using MS office 2000. I use query to import a list of client names and their individual contract numbers from an a billable report which is in a separate excel workbook.
EX:

15 ABC
30 Group
12 Joe Smith Co.

I then take this info and put it into a chart. My problem is that each new week, I create a new billable report worksheet. Currently my query data is coming from 071407 but now I want it to come from 072807 and so on and so forth. How can I change this? (And if so, automatically would be great).



I just don't know what to fill in after sTabName = and
sQuery =

Any help?

 
Old August 6th, 2007, 07:57 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

sXS = CStr(Format(Date, "mmddyy"))

Here Date Replaces the Sheet No

sTabName = "[" & sXS & "$]"

Other than that you need not do anything. Can you give the Names of the sheet?

Regards
Shasur

http://www.dotnetdud.blogspot.com
 
Old August 7th, 2007, 08:47 PM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The sheet name is 081107.

 
Old August 7th, 2007, 11:43 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Kate

The code should take care of your needs.

As the sheet name is 081107

sXS = CStr(Format(Date, "mmddyy"))

will get you 080807 (Today's date 08-Aug-07)

Here Date Replaces the Sheet No

sTabName = "[" & sXS & "$]"

sTabName will be the formatted sheet name.

Hence sQuery = "Select * From " & sTabName & ";" ' will fetch you the records of that particular date

If you want for some series of dates, you can used DateAdd function to increment the date value



http://www.dotnetdud.blogspot.com









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.