Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 148
Default Change Day to Month - VBA

Hi,

I got this macro from this NG to promt a password for a particular "day".
How do you change the macro to a particular "month and year".

from (#9/10/2007#) to Sep 2007
from (#9/11/2007#) to Oct 2007
from (#9/12/2007#) to Nov 2007

The format from vba help, "month(#9/10/2007#)" did not work.

Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String

arrPwords(1, 1) = (#9/10/2007#)
arrPwords(2, 1) = (#9/11/2007#)
arrPwords(3, 1) = (#9/12/2007#)
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = CStr(Application.VLookup(Date, arrPwords, 2, 0))
MsgBox strPWord
End Sub

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Change Day to Month - VBA

It looks like you could change (#9/10/2007#) to ("Sep 2007"), etc. and
then change strPWord = CStr(Application.VLookup(Date, arrPwords, 2,
0)) to strPWord = CStr(Application.VLookup(format(Date,"mmm yyyy"),
arrPwords, 2, 0)).

Hope this helps.
Jason


On Sep 10, 11:00 am, Danny wrote:
Hi,

I got this macro from this NG to promt a password for a particular "day".
How do you change the macro to a particular "month and year".

from (#9/10/2007#) to Sep 2007
from (#9/11/2007#) to Oct 2007
from (#9/12/2007#) to Nov 2007

The format from vba help, "month(#9/10/2007#)" did not work.

Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String

arrPwords(1, 1) = (#9/10/2007#)
arrPwords(2, 1) = (#9/11/2007#)
arrPwords(3, 1) = (#9/12/2007#)
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = CStr(Application.VLookup(Date, arrPwords, 2, 0))
MsgBox strPWord
End Sub

Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 148
Default Change Day to Month - VBA

Hi Jason,

When I changed it to ("Sep 2007"), it automatically changes to (#9/1/2007#).
When I ran the macro, it pops up, Error 2042.

Can you please take a look at again? Thank you.

"Jason" wrote:

It looks like you could change (#9/10/2007#) to ("Sep 2007"), etc. and
then change strPWord = CStr(Application.VLookup(Date, arrPwords, 2,
0)) to strPWord = CStr(Application.VLookup(format(Date,"mmm yyyy"),
arrPwords, 2, 0)).

Hope this helps.
Jason


On Sep 10, 11:00 am, Danny wrote:
Hi,

I got this macro from this NG to promt a password for a particular "day".
How do you change the macro to a particular "month and year".

from (#9/10/2007#) to Sep 2007
from (#9/11/2007#) to Oct 2007
from (#9/12/2007#) to Nov 2007

The format from vba help, "month(#9/10/2007#)" did not work.

Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String

arrPwords(1, 1) = (#9/10/2007#)
arrPwords(2, 1) = (#9/11/2007#)
arrPwords(3, 1) = (#9/12/2007#)
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = CStr(Application.VLookup(Date, arrPwords, 2, 0))
MsgBox strPWord
End Sub

Thank you.




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Change Day to Month - VBA

Danny,
This appears to work for me:

Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String

arrPwords(1, 1) = ("Sep 2007")
arrPwords(2, 1) = ("Oct 2007")
arrPwords(3, 1) = ("Nov 2007")
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = Application.VLookup(Format(Date, "mmm yyyy"), arrPwords, 2,
0)
MsgBox strPWord
End Sub

If you copy and paste this into a module, does it still give you that
error?

On Sep 10, 1:52 pm, Danny wrote:
Hi Jason,

When I changed it to ("Sep 2007"), it automatically changes to (#9/1/2007#).
When I ran the macro, it pops up, Error 2042.

Can you please take a look at again? Thank you.

"Jason" wrote:
It looks like you could change (#9/10/2007#) to ("Sep 2007"), etc. and
then change strPWord = CStr(Application.VLookup(Date, arrPwords, 2,
0)) to strPWord = CStr(Application.VLookup(format(Date,"mmm yyyy"),
arrPwords, 2, 0)).


Hope this helps.
Jason


On Sep 10, 11:00 am, Danny wrote:
Hi,


I got this macro from this NG to promt a password for a particular "day".
How do you change the macro to a particular "month and year".


from (#9/10/2007#) to Sep 2007
from (#9/11/2007#) to Oct 2007
from (#9/12/2007#) to Nov 2007


The format from vba help, "month(#9/10/2007#)" did not work.


Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String


arrPwords(1, 1) = (#9/10/2007#)
arrPwords(2, 1) = (#9/11/2007#)
arrPwords(3, 1) = (#9/12/2007#)
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = CStr(Application.VLookup(Date, arrPwords, 2, 0))
MsgBox strPWord
End Sub


Thank you.



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 148
Default Change Day to Month - VBA

Hi Jason,

This time it worked perfectly. Just taking out the "CStr" before the
Applicatio.Vlookup did it.

Thanks a lot!



"Jason" wrote:

Danny,
This appears to work for me:

Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String

arrPwords(1, 1) = ("Sep 2007")
arrPwords(2, 1) = ("Oct 2007")
arrPwords(3, 1) = ("Nov 2007")
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = Application.VLookup(Format(Date, "mmm yyyy"), arrPwords, 2,
0)
MsgBox strPWord
End Sub

If you copy and paste this into a module, does it still give you that
error?

On Sep 10, 1:52 pm, Danny wrote:
Hi Jason,

When I changed it to ("Sep 2007"), it automatically changes to (#9/1/2007#).
When I ran the macro, it pops up, Error 2042.

Can you please take a look at again? Thank you.

"Jason" wrote:
It looks like you could change (#9/10/2007#) to ("Sep 2007"), etc. and
then change strPWord = CStr(Application.VLookup(Date, arrPwords, 2,
0)) to strPWord = CStr(Application.VLookup(format(Date,"mmm yyyy"),
arrPwords, 2, 0)).


Hope this helps.
Jason


On Sep 10, 11:00 am, Danny wrote:
Hi,


I got this macro from this NG to promt a password for a particular "day".
How do you change the macro to a particular "month and year".


from (#9/10/2007#) to Sep 2007
from (#9/11/2007#) to Oct 2007
from (#9/12/2007#) to Nov 2007


The format from vba help, "month(#9/10/2007#)" did not work.


Sub PWforDate()
Dim arrPwords(1 To 3, 1 To 2) As Variant
Dim strPWord As String


arrPwords(1, 1) = (#9/10/2007#)
arrPwords(2, 1) = (#9/11/2007#)
arrPwords(3, 1) = (#9/12/2007#)
arrPwords(1, 2) = 1234
arrPwords(2, 2) = 2345
arrPwords(3, 2) = 3456
strPWord = CStr(Application.VLookup(Date, arrPwords, 2, 0))
MsgBox strPWord
End Sub


Thank you.




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
6 month annualized % change [email protected] Excel Discussion (Misc queries) 1 February 28th 07 04:03 PM
How do I put a Month into a cell and have the cells below change Cathy in Florida Excel Discussion (Misc queries) 1 July 14th 06 07:48 PM
How do you change the year but not the month automatically? Autumn Dreams Excel Discussion (Misc queries) 3 May 28th 06 05:41 PM
how do i change the format for excel to day-month swy Excel Worksheet Functions 1 July 2nd 05 07:09 AM
month to month % change Susan Excel Worksheet Functions 2 May 20th 05 08:18 PM


All times are GMT +1. The time now is 05:45 AM.

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

About Us

"It's about Microsoft Excel"