Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Extract a YearMonth value from a Date

I want to populate a Month Column (with the format YMM) from the
adjacent Date column,
through a loop which would translate a date like 8/15/2007 to 708.
The Excel formula is Year(DateField)*100+Month(Datefield)-200000
Now , I want to incorporate this logic in my loop code, and for good
measure, add an IsDate test.
I am still a newbie. I tried to get the help of the Macro Recorder,
but I am stuck.
Can you help me with this code ?. Thank you.

Dim RowNdx As Long: Dim LastRow As Long: LastRow =
ActiveSheet.UsedRange.Rows.Count
For RowNdx = LastRow To 2 Step -1
If IsDate(Cells(RowNdx, "Z").Value) Then
Cells(RowNdx, "Y").Value = "=YEAR((Cells(RowNdx,
'Z').Value)*100+MONTH((Cells (RowNdx, 'Z').Value)-200000"
Next RowNdx

Celeste

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Extract a YearMonth value from a Date

One way:

Dim rCell As Range
For Each rCell In Range("Z2:Z" & _
Range("Z" & Rows.Count).End(xlUp).Row)
With rCell
If IsDate(.Value) Then _
.Offset(0, -1).Value = Right(Format(.Value, "YYMM"), 3)
End With
Next rCell

In article . com,
u473 wrote:

I want to populate a Month Column (with the format YMM) from the
adjacent Date column,
through a loop which would translate a date like 8/15/2007 to 708.
The Excel formula is Year(DateField)*100+Month(Datefield)-200000
Now , I want to incorporate this logic in my loop code, and for good
measure, add an IsDate test.
I am still a newbie. I tried to get the help of the Macro Recorder,
but I am stuck.
Can you help me with this code ?. Thank you.

Dim RowNdx As Long: Dim LastRow As Long: LastRow =
ActiveSheet.UsedRange.Rows.Count
For RowNdx = LastRow To 2 Step -1
If IsDate(Cells(RowNdx, "Z").Value) Then
Cells(RowNdx, "Y").Value = "=YEAR((Cells(RowNdx,
'Z').Value)*100+MONTH((Cells (RowNdx, 'Z').Value)-200000"
Next RowNdx

Celeste

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Extract a YearMonth value from a Date

Woww !!!. I do appreciate your solution.
I want to extend this code further, using other postings,
but I get Errors in trying to sum Columns.
I am also trying to copy Entire Row for Invalid Date on separate
Worksheet
Help appreciated.

Dim rCell As Range
Dim myRow As Long
For Each rCell In Range("Z2:Z" & _
Range("Z" & Rows.Count).End(xlUp).Row)
With rCell
If IsDate(.Value) Then _
.Offset(0, -1).Value = Right(Format(.Value, "YYMM"),
3)
' Sum 5,6,... Columns to 16 Column . Error on next
statement
.Offset(0, 16).Value = Offset(0, 5).Value + Offset(0,
6).Value
'If Date is greater than Today, Copy Entire row to
Invalid Dates worksheet
'If ActiveCell.Value Now()
' myRow = Sheets("InvalidDates").Cells(Rows.Count,
3).End(xlUp)(2).Row
' Intersect(Target.EntireRow,
ActiveSheet.UsedRange).Copy

Else
.Entire.row.Delete
End If

End With
Next rCell

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
EXTRACT MONTH FROM DATE SSJ New Users to Excel 5 March 7th 08 05:55 PM
Extract Date christmaslog Excel Worksheet Functions 1 February 19th 06 10:28 AM
extract name when a date in another cell gets near cityfc Excel Discussion (Misc queries) 1 November 9th 05 07:40 PM
extract date from the most current date Cali00 Excel Discussion (Misc queries) 1 April 13th 05 02:05 PM
Extract date from cell Eric Excel Worksheet Functions 3 November 4th 04 06:37 PM


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