Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 4
Default VBA variable definition help needed.

Hi all! I have run across an issue with data retrieval. At the company I
work for, the year runs from November 1, 2008-October 31, 2009. In one of
our forms, the user will enter a date such as 11/1/2008 in cell B2. Our path
for data retrieval is m:\2009\SALES TEAM\Midwest Territory.xls. For two
months (nov and dec) the year will be 2008. How can I change the mYear
variable below to accomodate the year 2008 when it actually resides in the
2009 folder? My apologies, I'm very new to excel and VBA. Thanks.

sdate = Range("B2").Value

mYear = Format(sdate, "yyyy")
mPath = "='m:\" & mYear & "\SALES TEAM\Midwest Territory.xls"
--
jenn k
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 35,218
Default VBA variable definition help needed.

Dim sDate As Date
Dim mYear As Long

sDate = ActiveSheet.Range("B2").Value
'for testing
'sDate = DateSerial(2008, 11, 1)

mYear = Year(sDate) - CBool((Month(sDate) 10))

MsgBox mYear

(In VBA, true is equal to -1)



jenn k wrote:

Hi all! I have run across an issue with data retrieval. At the company I
work for, the year runs from November 1, 2008-October 31, 2009. In one of
our forms, the user will enter a date such as 11/1/2008 in cell B2. Our path
for data retrieval is m:\2009\SALES TEAM\Midwest Territory.xls. For two
months (nov and dec) the year will be 2008. How can I change the mYear
variable below to accomodate the year 2008 when it actually resides in the
2009 folder? My apologies, I'm very new to excel and VBA. Thanks.

sdate = Range("B2").Value

mYear = Format(sdate, "yyyy")
mPath = "='m:\" & mYear & "\SALES TEAM\Midwest Territory.xls"
--
jenn k


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1,358
Default VBA variable definition help needed.

Set up a variable in excel, Insert|Name|Define
YrFlder: =EDATE(B2,2)

Then change your variable in vba to the following:
sdate = Range(YrFldr).Value

I am sure there are other 'cleaner' ways, but this should accomplish what
you need it to do.

Hope this helps.

--
John C


"jenn k" wrote:

Hi all! I have run across an issue with data retrieval. At the company I
work for, the year runs from November 1, 2008-October 31, 2009. In one of
our forms, the user will enter a date such as 11/1/2008 in cell B2. Our path
for data retrieval is m:\2009\SALES TEAM\Midwest Territory.xls. For two
months (nov and dec) the year will be 2008. How can I change the mYear
variable below to accomodate the year 2008 when it actually resides in the
2009 folder? My apologies, I'm very new to excel and VBA. Thanks.

sdate = Range("B2").Value

mYear = Format(sdate, "yyyy")
mPath = "='m:\" & mYear & "\SALES TEAM\Midwest Territory.xls"
--
jenn k

  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1,358
Default VBA variable definition help needed.

Should be
YrFldr: =EDATE($B$2,2)
--
John C


"John C" wrote:

Set up a variable in excel, Insert|Name|Define
YrFlder: =EDATE(B2,2)

Then change your variable in vba to the following:
sdate = Range(YrFldr).Value

I am sure there are other 'cleaner' ways, but this should accomplish what
you need it to do.

Hope this helps.

--
John C


"jenn k" wrote:

Hi all! I have run across an issue with data retrieval. At the company I
work for, the year runs from November 1, 2008-October 31, 2009. In one of
our forms, the user will enter a date such as 11/1/2008 in cell B2. Our path
for data retrieval is m:\2009\SALES TEAM\Midwest Territory.xls. For two
months (nov and dec) the year will be 2008. How can I change the mYear
variable below to accomodate the year 2008 when it actually resides in the
2009 folder? My apologies, I'm very new to excel and VBA. Thanks.

sdate = Range("B2").Value

mYear = Format(sdate, "yyyy")
mPath = "='m:\" & mYear & "\SALES TEAM\Midwest Territory.xls"
--
jenn k

  #5   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 4
Default VBA variable definition help needed.

Thank you both very much for your help! I will give it a whirl.
--
jenn k


"John C" wrote:

Should be
YrFldr: =EDATE($B$2,2)
--
John C


"John C" wrote:

Set up a variable in excel, Insert|Name|Define
YrFlder: =EDATE(B2,2)

Then change your variable in vba to the following:
sdate = Range(YrFldr).Value

I am sure there are other 'cleaner' ways, but this should accomplish what
you need it to do.

Hope this helps.

--
John C


"jenn k" wrote:

Hi all! I have run across an issue with data retrieval. At the company I
work for, the year runs from November 1, 2008-October 31, 2009. In one of
our forms, the user will enter a date such as 11/1/2008 in cell B2. Our path
for data retrieval is m:\2009\SALES TEAM\Midwest Territory.xls. For two
months (nov and dec) the year will be 2008. How can I change the mYear
variable below to accomodate the year 2008 when it actually resides in the
2009 folder? My apologies, I'm very new to excel and VBA. Thanks.

sdate = Range("B2").Value

mYear = Format(sdate, "yyyy")
mPath = "='m:\" & mYear & "\SALES TEAM\Midwest Territory.xls"
--
jenn k



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
VBA Range definition: Code needed David B Excel Discussion (Misc queries) 8 September 25th 06 06:40 PM
f statistic, p value definition Regression analysis terms Excel Worksheet Functions 1 June 8th 06 09:11 PM
$ definition nicolebelle Excel Worksheet Functions 1 November 18th 05 01:44 PM
Sum product help needed with an extra variable please and thankyou Anthony Excel Worksheet Functions 6 July 12th 05 04:31 PM
The definition of.... Ursula Excel Worksheet Functions 2 February 16th 05 04:14 PM


All times are GMT +1. The time now is 01:30 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"