Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Getting error using Month()

Hi,

I am confused and need some assistance.
In my Vba code I am trying to verify if todays month is different than
the one in cell.
Problem is I am getting an error using the Month().

MsgBox (Month(MainWorksSheet.Range("B19").Value))

The code above gives me the error that the Object doesnt support the
property.
The range value is a date 2008/07/02.

Using the Year() function it works and returns 2008 as it should.
What am I missing with the month function?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Getting error using Month()

Try this

MsgBox Month(Sheets("mainworksheet").Range("B19").Value)

Mike

" wrote:

Hi,

I am confused and need some assistance.
In my Vba code I am trying to verify if todays month is different than
the one in cell.
Problem is I am getting an error using the Month().

MsgBox (Month(MainWorksSheet.Range("B19").Value))

The code above gives me the error that the Object doesnt support the
property.
The range value is a date 2008/07/02.

Using the Year() function it works and returns 2008 as it should.
What am I missing with the month function?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Getting error using Month()

Hi,

Mainworksheet is a Worksheet variable that was defined the sheet name
that I need to work on.
I dont think that is the problem.
The problem is with the month() function that gives an error.
I can get the date result from MainWorksSheet.Range("B19").Value, but
month() complains about it.
Cell B19 is defined as date and it contains todays date on the format
of "2008/02/08"
Why can't month() work with it??


On Feb 8, 4:31*am, Mike H wrote:
Try this

MsgBox Month(Sheets("mainworksheet").Range("B19").Value)

Mike



" wrote:
Hi,


I am confused and need some assistance.
In my Vba code I am trying to verify if todays month is different than
the one in cell.
Problem is I am getting an error using the Month().


MsgBox (Month(MainWorksSheet.Range("B19").Value))


The code above gives me the error that the Object doesnt support the
property.
The *range value is a date 2008/07/02.


Using the Year() function it works and returns 2008 as it should.
What am I missing with the month function?


Thanks- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Getting error using Month()

On Fri, 8 Feb 2008 08:20:23 -0800 (PST), "
wrote:

Mainworksheet is a Worksheet variable that was defined the sheet name
that I need to work on.
I dont think that is the problem.
The problem is with the month() function that gives an error.
I can get the date result from MainWorksSheet.Range("B19").Value, but
month() complains about it.
Cell B19 is defined as date and it contains todays date on the format
of "2008/02/08"
Why can't month() work with it??


I canNOT reproduce your problem with this:

=================================
Option Explicit
Sub foo()
Dim MainWorksSheet As Worksheet
Set MainWorksSheet = ActiveSheet
MsgBox (Month(MainWorksSheet.Range("B19").Value))
End Sub
====================================

Let us see some more of your code.
--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Getting error using Month()

Here is what I have in module1:

A few notes about it.
I noticed that the Public MainWorkSheet is missing a "s" and it is not
defined inside the open sub.
Notices the "s" on the line Set MainWorksSheet .
If I try to fix this, this causes me another problem and still doesnt
solve my month() problem.

If i declare a public MainWorksSheet or a DIM MainWorksSheet as
Worksheet inside the sub then
MainWorksSheet.CommandButtonAdd.Enabled = True
MainWorksSheet.CommandButtonMakeBusy.Caption = "Start"
stops working????
(These are two buttons created in the sheet for interaction using the
toolbox)
Untli someones explain this to me I dont know what is going on.

Thanks for the help.

=================================
Option Explicit
Public MainWorkSheet as worksheet

sub open ()

Dim StartWeekRange, EndWeekRange As Range
Dim TempWeekday As Integer
Dim WorkingPath As String
Set MainWorksSheet = ThisWorkbook.Worksheets("Main")

Set StartWeekRange = MainWorksSheet.Range("H2")
Set EndWeekRange = MainWorksSheet.Range("J2")

MainWorksSheet.CommandButtonAdd.Enabled = True
MainWorksSheet.CommandButtonMakeBusy.Caption = "Start"


MainWorksSheet.TextBoxAccount.Value = ""
MainWorksSheet.TextBoxNotes.Value = ""

TodayWeekDay = ""
TempWeekday = Weekday(Date)
'if new month call UpdateWeeklyValues("New Month")

'new week

'MsgBox Month(Sheets("Main").Range("b19").Value)

StartWeekRange.Value = (Date - (TempWeekday - 2))
EndWeekRange.Value = (Date + (7 - TempWeekday))

'Dim TempMonth
'If Date < DateSerial(Year(Date), Month(Date) + 1, 0) Then
'MsgBox (Month(MainWorksSheet.Range("B19").Value))
'End If
'TempMonth = Month(MainWorksSheet.Range("B19").Value)
'TempMonth = (DateSerial(Year(Date),
Month(MainWorksSheet.Range("B19").Value), 1)) '
Month(MainWorksSheet.Range("B19").Value)

'If Month(MainWorksSheet.Range("B19").Value) <
(DateSerial(Year(Date), Month(Date), 1)) Then
'UpdateWeeklyValues ("New Month")
'End If


If MainWorksSheet.Range("B19").Value < Date Then
'add another work day to the monthly sheet
ThisWorkbook.Worksheets("MonthlyTrack").Range("L8" ).Value =
ThisWorkbook.Worksheets("MonthlyTrack").Range("L8" ).Value + 1

MainWorksSheet.LabelMakeBusy.Caption = "00:00:00"
MainWorksSheet.Range("B19").Value = Date
End If

MainWorksSheet.Activate
MainWorksSheet.Range("A1").Select

end sub


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Getting error using Month()

On Fri, 8 Feb 2008 12:48:02 -0800 (PST), "
wrote:

Here is what I have in module1:

A few notes about it.
I noticed that the Public MainWorkSheet is missing a "s" and it is not
defined inside the open sub.
Notices the "s" on the line Set MainWorksSheet .
If I try to fix this, this causes me another problem and still doesnt
solve my month() problem.

If i declare a public MainWorksSheet or a DIM MainWorksSheet as
Worksheet inside the sub then
MainWorksSheet.CommandButtonAdd.Enabled = True
MainWorksSheet.CommandButtonMakeBusy.Caption = "Start"
stops working????
(These are two buttons created in the sheet for interaction using the
toolbox)
Untli someones explain this to me I dont know what is going on.

Thanks for the help.

=================================
Option Explicit
Public MainWorkSheet as worksheet

sub open ()

Dim StartWeekRange, EndWeekRange As Range
Dim TempWeekday As Integer
Dim WorkingPath As String
Set MainWorksSheet = ThisWorkbook.Worksheets("Main")

Set StartWeekRange = MainWorksSheet.Range("H2")
Set EndWeekRange = MainWorksSheet.Range("J2")

MainWorksSheet.CommandButtonAdd.Enabled = True
MainWorksSheet.CommandButtonMakeBusy.Caption = "Start"


MainWorksSheet.TextBoxAccount.Value = ""
MainWorksSheet.TextBoxNotes.Value = ""

TodayWeekDay = ""
TempWeekday = Weekday(Date)
'if new month call UpdateWeeklyValues("New Month")

'new week

'MsgBox Month(Sheets("Main").Range("b19").Value)

StartWeekRange.Value = (Date - (TempWeekday - 2))
EndWeekRange.Value = (Date + (7 - TempWeekday))

'Dim TempMonth
'If Date < DateSerial(Year(Date), Month(Date) + 1, 0) Then
'MsgBox (Month(MainWorksSheet.Range("B19").Value))
'End If
'TempMonth = Month(MainWorksSheet.Range("B19").Value)
'TempMonth = (DateSerial(Year(Date),
Month(MainWorksSheet.Range("B19").Value), 1)) '
Month(MainWorksSheet.Range("B19").Value)

'If Month(MainWorksSheet.Range("B19").Value) <
(DateSerial(Year(Date), Month(Date), 1)) Then
'UpdateWeeklyValues ("New Month")
'End If


If MainWorksSheet.Range("B19").Value < Date Then
'add another work day to the monthly sheet
ThisWorkbook.Worksheets("MonthlyTrack").Range("L8" ).Value =
ThisWorkbook.Worksheets("MonthlyTrack").Range("L8 ").Value + 1

MainWorksSheet.LabelMakeBusy.Caption = "00:00:00"
MainWorksSheet.Range("B19").Value = Date
End If

MainWorksSheet.Activate
MainWorksSheet.Range("A1").Select

end sub


I guess I'm not sure what you are presenting.

Your Sub does not work at all on my system. Open is a keyword so there's a
naming problem right at the start.

Certainly, with a date in B19, and MainWorksSheet set to ActiveSheet, the
following works properly:

Month(MainWorksSheet.Range("B19").Value)

I wish I could help you more but perhaps if you just start with a small part of
your Sub, get it working, and then add on the other required segments, you will
have better luck.


--ron
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Getting error using Month()

Can someone help me with this?

I dont know why the month() doesnt work and I need to compare todays
date with a date on a cell and match the month.
If the month are the same then do something, if it is different then
do something else.

Thanks

On Feb 8, 1:58*am, " wrote:
Hi,

I am confused and need some assistance.
In my Vba code I am trying to verify if todays month is different than
the one in cell.
Problem is I am getting an error using the Month().

MsgBox (Month(MainWorksSheet.Range("B19").Value))

The code above gives me the error that the Object doesnt support the
property.
The *range value is a date 2008/07/02.

Using the Year() function it works and returns 2008 as it should.
What am I missing with the month function?

Thanks


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Getting error using Month()

I can send the file via email to anyone wanting to take a crack at it?
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
Grouping daily transactions in a pivot table by month - CANNOT GROUPTHAT SELECTION ERROR Dave K Excel Discussion (Misc queries) 1 February 7th 09 05:56 PM
excel to make the days cary over month to month automaticly GARY New Users to Excel 1 April 19th 08 06:05 PM
Excel 2003 month to month data change grid Chad[_2_] Excel Discussion (Misc queries) 2 February 15th 08 01:36 AM
copy worksheet from previous month and rename to current month Dan E. Excel Programming 4 December 8th 05 09:40 PM
transfer cell $ amount to other sheet month-to-month without overc Colin2u Excel Discussion (Misc queries) 1 July 28th 05 02:36 AM


All times are GMT +1. The time now is 05:57 PM.

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"