ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Date Format (https://www.excelbanter.com/excel-programming/436529-date-format.html)

Risky Dave

Date Format
 
Hi,

Please explain what is wrong with this:

Dim sMonth as string

smonth = format(Sheets("ChartsP").Range("a1").Value, "mmm-yy")

I am getting an error message: "Wrong number of arguments or invalid
property assignment

TIA

Dave

Jacob Skaria

Date Format
 
The line looks OK. Is that all you have..Where is this code placed?

If this post helps click Yes
---------------
Jacob Skaria


"Risky Dave" wrote:

Hi,

Please explain what is wrong with this:

Dim sMonth as string

smonth = format(Sheets("ChartsP").Range("a1").Value, "mmm-yy")

I am getting an error message: "Wrong number of arguments or invalid
property assignment

TIA

Dave


Risky Dave

Date Format
 
Jacob,

Thanks for the quick reply. This is the start of the code (the whole things
is about 80 lines, so I won't post it all here):

Dim sMonth As String
Dim sLastEntry As String
Dim lNetScore As Long
Dim arrSum As Variant
Dim lriskcount As Long
Dim lRowNum As Long

Application.ScreenUpdating = False

' check if it is the same month
Set rCurrentCell = Sheets("ChartsP").Range("n2")
Do
Set rCurrentCell = rCurrentCell.Offset(1, 0)
Loop Until rCurrentCell.Value = ""
Set rCurrentCell = rCurrentCell.Offset(-1, 0)
sMonth = Sheets("ChartsP").Range("a1").Value
Do
sLastEntry = rCurrentCell.Value
If sMonth = sLastEntry Then
' do stuff here
Loop
Application.ScreenUpdating = True
End Sub

What I am trying to do is read the value of a specified cell that contains
Today() and format it as "mmm-yy" to a string variable (sMonth). Then I want
to compare sMonth with another string variable (sLastEntry) which gets it
content from a different cell and is formatted in the same way.

Hope this makes sense

Dave

"Jacob Skaria" wrote:

The line looks OK. Is that all you have..Where is this code placed?

If this post helps click Yes
---------------
Jacob Skaria


"Risky Dave" wrote:

Hi,

Please explain what is wrong with this:

Dim sMonth as string

smonth = format(Sheets("ChartsP").Range("a1").Value, "mmm-yy")

I am getting an error message: "Wrong number of arguments or invalid
property assignment

TIA

Dave


Jacob Skaria

Date Format
 
You dont need to loop if you are trying to get the last entry in Col N

'Try (if both cells are in excel date format)
If Sheets("ChartsP").Cells(Rows.Count, "N").End(xlUp).Value = _
Sheets("ChartsP").Range("a1").Value Then

End If


If this post helps click Yes
---------------
Jacob Skaria


"Risky Dave" wrote:

Jacob,

Thanks for the quick reply. This is the start of the code (the whole things
is about 80 lines, so I won't post it all here):

Dim sMonth As String
Dim sLastEntry As String
Dim lNetScore As Long
Dim arrSum As Variant
Dim lriskcount As Long
Dim lRowNum As Long

Application.ScreenUpdating = False

' check if it is the same month
Set rCurrentCell = Sheets("ChartsP").Range("n2")
Do
Set rCurrentCell = rCurrentCell.Offset(1, 0)
Loop Until rCurrentCell.Value = ""
Set rCurrentCell = rCurrentCell.Offset(-1, 0)
sMonth = Sheets("ChartsP").Range("a1").Value
Do
sLastEntry = rCurrentCell.Value
If sMonth = sLastEntry Then
' do stuff here
Loop
Application.ScreenUpdating = True
End Sub

What I am trying to do is read the value of a specified cell that contains
Today() and format it as "mmm-yy" to a string variable (sMonth). Then I want
to compare sMonth with another string variable (sLastEntry) which gets it
content from a different cell and is formatted in the same way.

Hope this makes sense

Dave

"Jacob Skaria" wrote:

The line looks OK. Is that all you have..Where is this code placed?

If this post helps click Yes
---------------
Jacob Skaria


"Risky Dave" wrote:

Hi,

Please explain what is wrong with this:

Dim sMonth as string

smonth = format(Sheets("ChartsP").Range("a1").Value, "mmm-yy")

I am getting an error message: "Wrong number of arguments or invalid
property assignment

TIA

Dave



All times are GMT +1. The time now is 03:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com