Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Extracting Year from date cell

The contents of the cell that I'm copying (and then pasting) in the formula
below is a date:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Prior to pasting, however, I need to extract just the Year value. But as
best as I can tell, VBA does not support the YEAR function.

Can someone kindly tell me how I can modify my code to extract and paste
just the Year? Thanks in advance for any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Extracting Year from date cell

Sub sistence()
Dim dd As Date
dd = Date
MsgBox (Format(dd, "yyyy"))
End Sub

--
Gary''s Student - gsnu200740


"Bob" wrote:

The contents of the cell that I'm copying (and then pasting) in the formula
below is a date:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Prior to pasting, however, I need to extract just the Year value. But as
best as I can tell, VBA does not support the YEAR function.

Can someone kindly tell me how I can modify my code to extract and paste
just the Year? Thanks in advance for any help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Extracting Year from date cell

Maybe your "date" isn't really a date.

This works for me:

Option Explicit
Sub testme()
MsgBox Year(Date)
End Sub

But you can't copy|Paste special|just the year of a date.

dim myYear as long

myyear = year(Worksheets(Sheet1Name).Cells(Sheet1DateRowPoi nter, h).value)

Worksheets(Sheet2Name).Cells(Sheet2RowPointer, Sheet2YearColPointer).value _
= myyear

(With no checking at all)

Bob wrote:

The contents of the cell that I'm copying (and then pasting) in the formula
below is a date:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Prior to pasting, however, I need to extract just the Year value. But as
best as I can tell, VBA does not support the YEAR function.

Can someone kindly tell me how I can modify my code to extract and paste
just the Year? Thanks in advance for any help.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Extracting Year from date cell

Dave,
Thanks for the help. I verified that the date I'm copying is truly a date,
so the line:

myYear = Year(Worksheets(Sheet1Name).Cells(Sheet1DateRowPoi nter, h).Value)

does correctly "strip out" the year portion of the date.

Now that I have the year portion stored in myYear, could you kindly tell me
how to modify the line below so that it pastes myYear:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Thanks again,
Bob


"Dave Peterson" wrote:

Maybe your "date" isn't really a date.

This works for me:

Option Explicit
Sub testme()
MsgBox Year(Date)
End Sub

But you can't copy|Paste special|just the year of a date.

dim myYear as long

myyear = year(Worksheets(Sheet1Name).Cells(Sheet1DateRowPoi nter, h).value)

Worksheets(Sheet2Name).Cells(Sheet2RowPointer, Sheet2YearColPointer).value _
= myyear

(With no checking at all)

Bob wrote:

The contents of the cell that I'm copying (and then pasting) in the formula
below is a date:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Prior to pasting, however, I need to extract just the Year value. But as
best as I can tell, VBA does not support the YEAR function.

Can someone kindly tell me how I can modify my code to extract and paste
just the Year? Thanks in advance for any help.


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Extracting Year from date cell

Dave,
Please ignore my previous post. I just realized that you already provided
me with the answer:

Worksheets(Sheet2Name).Cells(Sheet2RowPointer, Sheet2YearColPointer).value _
= myyear

Thanks again for all your help!
Bob


"Bob" wrote:

Dave,
Thanks for the help. I verified that the date I'm copying is truly a date,
so the line:

myYear = Year(Worksheets(Sheet1Name).Cells(Sheet1DateRowPoi nter, h).Value)

does correctly "strip out" the year portion of the date.

Now that I have the year portion stored in myYear, could you kindly tell me
how to modify the line below so that it pastes myYear:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Thanks again,
Bob


"Dave Peterson" wrote:

Maybe your "date" isn't really a date.

This works for me:

Option Explicit
Sub testme()
MsgBox Year(Date)
End Sub

But you can't copy|Paste special|just the year of a date.

dim myYear as long

myyear = year(Worksheets(Sheet1Name).Cells(Sheet1DateRowPoi nter, h).value)

Worksheets(Sheet2Name).Cells(Sheet2RowPointer, Sheet2YearColPointer).value _
= myyear

(With no checking at all)

Bob wrote:

The contents of the cell that I'm copying (and then pasting) in the formula
below is a date:

Worksheets(Sheet1Name).Cells(Sheet1DateRowPointer, h). _
Copy Worksheets(Sheet2Name).Cells(Sheet2RowPointer, _
Sheet2YearColPointer)

Prior to pasting, however, I need to extract just the Year value. But as
best as I can tell, VBA does not support the YEAR function.

Can someone kindly tell me how I can modify my code to extract and paste
just the Year? Thanks in advance for any help.


--

Dave Peterson

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
Extracting date from Date and Time formatted cell Aviral Sharma Excel Discussion (Misc queries) 2 March 6th 09 05:04 AM
Help w/formula to add 1 year to cell (date done) date due? GregJ Excel Worksheet Functions 3 September 20th 06 01:05 PM
extracting year from a date grendel Excel Discussion (Misc queries) 3 March 25th 06 04:12 PM
extract year from the date in a cell DKY Excel Worksheet Functions 7 March 17th 06 07:07 PM
Extracting the Month from the Date in other cell RustyR Excel Programming 3 December 15th 04 03:11 PM


All times are GMT +1. The time now is 12:34 PM.

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"