Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default How to get the first day of the previous month...

Hi,

I have a variable called CDAT. This is a date that corresponds to a
cell reference. In my code, I want to [continually] modify this
variable to give me the first day of the previous month. i.e. I want
to modify it to equal 07/01/2008, then modify it to equal 06/01/2008
then 05/01/2008 etc.

I have been playing around with the eomonth worksheet function in my
code, but as weird as it is, it does not give me the same response as
when I put it in a cell. I actually think it might be that I am using
the 'day' formula in my code and expecting to get the same response as
I would in worksheetfunction. This is what I have.

Sub Modify_Table(ByVal cdat As Date)
Dim cdat As Date


cdat = Sheets("Data Layout").range("B35").Value
MsgBox cdat
cdat = cdat - Day(15)
MsgBox cdat
cdat = Application.WorksheetFunction.EoMonth(cdat, -2)
cdat = cdat + Day(1)
MsgBox cdat



ActiveSheet.ListObjects("WDT").range.AutoFilter field:=1,
Criteria1:="=" & cdat, Operator:=xlExpression


End Sub

Any help is much appreciated...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default How to get the first day of the previous month...

Nevermind...I figured it out...I used the following code, FYI.

If anyone knows a more efficient way to code this, please let me know
however! At present anything that works is wonderful.


Dim cdat As Date
Dim D As Integer



cdat = Sheets("Data Layout").range("B35").Value
MsgBox cdat
cdat = cdat - Day(15)
D = Day(cdat)
cdat = cdat - Day(D)

MsgBox cdat
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to get the first day of the previous month...

nit exactly sure what you want, but give this a try

Sub test()
Dim cdat As Date
Dim D As Integer
cdat = Sheets("Data Layout").Range("B35").Value
MsgBox cdat
cdat = DateSerial(Year(cdat), Month(cdat) - 1, Day(0))
D = Day(cdat)
cdat = cdat - Day(D)
MsgBox cdat
End Sub


--


Gary


"R Tanner" wrote in message
...
Nevermind...I figured it out...I used the following code, FYI.

If anyone knows a more efficient way to code this, please let me know
however! At present anything that works is wonderful.


Dim cdat As Date
Dim D As Integer



cdat = Sheets("Data Layout").range("B35").Value
MsgBox cdat
cdat = cdat - Day(15)
D = Day(cdat)
cdat = cdat - Day(D)

MsgBox cdat



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
3-Color Scale Vlookup for Current Month/Previous/Pre-Previous NeoFax Excel Discussion (Misc queries) 2 January 8th 10 07:04 PM
Retrieve data for previous 3, 6, 12 month given current month GB Excel Worksheet Functions 4 July 19th 07 11:58 PM
Previous Month End Tristan Excel Discussion (Misc queries) 7 September 9th 06 12:25 PM
copy worksheet from previous month and rename to current month Dan E. Excel Programming 4 December 8th 05 09:40 PM
End of previous month Steve Excel Programming 5 October 1st 04 02:46 PM


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