Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

I want to manipulate date entered in excel sheet using VB macro, ie want to
extract day, moth and year separately from the date entered in EXCEL sheet
(in dd-mm-yy format )and store it in three different variables. but since the
formats used in excel is dd-mm-yy and VB is mm/dd/yy could any body please
code a function to do the same Thanks very much

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200908/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

Sub test()
Dim dt As Date
Dim d As Long, m As Long, y As Long

Range("a1") = Now ' or Date

dt = Range("A1").Value

d = Day(dt)
m = Month(dt)
y = Year(dt)

Debug.Print d, m, y

End Sub

press ctrl-g to see the debug results in the Immediate window

Regards,
Peter T


"nanda via OfficeKB.com" <u54234@uwe wrote in message
news:9b2a3a8507635@uwe...
I want to manipulate date entered in excel sheet using VB macro, ie want
to
extract day, moth and year separately from the date entered in EXCEL sheet
(in dd-mm-yy format )and store it in three different variables. but since
the
formats used in excel is dd-mm-yy and VB is mm/dd/yy could any body please
code a function to do the same Thanks very much

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200908/1



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

if the cell value is a date, then in VBA use the DATE() MONTH() and YEAR()
functions ...they have nothign to do with what format you use

set target = range("A1")
msgbox "Year:" & year(target) & ", Month:" & month(target) & ", Day:" &
day(target)

"nanda via OfficeKB.com" wrote:

I want to manipulate date entered in excel sheet using VB macro, ie want to
extract day, moth and year separately from the date entered in EXCEL sheet
(in dd-mm-yy format )and store it in three different variables. but since the
formats used in excel is dd-mm-yy and VB is mm/dd/yy could any body please
code a function to do the same Thanks very much

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200908/1


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

On Aug 26, 10:44*am, "nanda via OfficeKB.com" <u54234@uwe wrote:
I want *to manipulate date entered in excel sheet using VB *macro, ie want to
extract day, moth and year separately from the date entered in EXCEL sheet
(in dd-mm-yy format )and store it in three different variables. but since the
formats used in excel is dd-mm-yy and VB is mm/dd/yy could any body please
code a *function to do the same Thanks very much

--
Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/excel-programming/200908/1


You can try with GemBox.Spreadsheet. It has methods to format date in
cells.
http://www.gemboxsoftware.com/GBSpreadsheet.htm
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

Thank you very much for the immediate reply.


But Im sorry to say that I coded my query in a wrong way. Actually I wanted
to know comparison of two dates of excel in macro, since there is mismatch
of formats (EXCEL :DD-MM-YY & VB:mm/dd/yy)

Could you help me coding - how to compare two dates in Macro.
Suppose A1 contains 28-11-00. I want to check whether the value in A1 is
LESS THAN 02-3-01 and greater than or equal to 16-12-98 .

Thanking you in anticipation

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200908/1



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

I wanted to know comparison of two dates of excel in macro, since there is
mismatch of formats (EXCEL :DD-MM-YY & VB:mm/dd/yy)

Could you please help me coding - how to compare two dates in Macro since i
am not an expert in macro
Suppose A1 contains 28-11-00. I want to check whether the value in A1 is
LESS THAN 02-3-01 and greater than or equal to 16-12-98 .

Thanking you in anticipation

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200908/1

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

thanks for the immediate response
But Im sorry to say that I coded my query in a wrong way. Actually I wanted
to know comparison of two dates of excel in macro, since there is mismatch
of formats (EXCEL :DD-MM-YY & VB:mm/dd/yy)

Could you help me coding - how to compare two dates in Macro.
Suppose A1 contains 28-11-00. I want to check whether the value in A1 is
LESS THAN 02-3-01 and greater than or equal to 16-12-98 .

--
Message posted via http://www.officekb.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

thanks for the immediate response
But Im sorry to say that I coded my query in a wrong way. Actually I wanted
to know comparison of two dates of excel in macro, since there is mismatch
of formats (EXCEL :DD-MM-YY & VB:mm/dd/yy)

Could you help me coding - how to compare two dates in Macro.
Suppose A1 contains 28-11-00. I want to check whether the value in A1 is
LESS THAN 02-3-01 and greater than or equal to 16-12-98 .

--
Message posted via http://www.officekb.com

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Date dd-mm-yy(EXCEL) manipulation in VB macro

On Sat, 29 Aug 2009 07:44:34 GMT, "lataa3 via OfficeKB.com" <u54234@uwe wrote:

Thank you very much for the immediate reply.


But I’m sorry to say that I coded my query in a wrong way. Actually I wanted
to know comparison of two dates of excel in macro, since there is mismatch
of formats (EXCEL :DD-MM-YY & VB:mm/dd/yy)

Could you help me coding - how to compare two dates in Macro.
Suppose A1 contains 28-11-00. I want to check whether the value in A1 is
LESS THAN 02-3-01 and greater than or equal to 16-12-98 .

Thanking you in anticipation


Excel stores dates as serial numbers beginning with 1 (= 1 Jan 1900)

The format only determines how that serial number is displayed. It is
completely irrelevant for what you want to do (assuming it has been entered as
an Excel date, and is not a text representation of the date).

Here is one way to do what you describe:

==========================
Option Explicit
Sub CompDate()
Dim d1 As Date, d2 As Date, d3 As Date
Dim bRes As Boolean

'Set up parameters for test
With Range("a1")
.NumberFormat = "dd-mm-yy"
.Value = DateSerial(2000, 11, 28)
End With

d2 = DateSerial(2001, 3, 2)
d3 = DateSerial(1998, 12, 16)

'Do the test
d1 = Range("A1").Value

If d1 < d2 And d1 = d3 Then
bRes = True
Else
bRes = False
End If

Debug.Print "Date comparison is " & bRes

End Sub
=================================

The above will return a True.
--ron
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
Date manipulation Vsn Excel Programming 0 April 22nd 06 05:52 PM
Date manipulation JE McGimpsey Excel Programming 1 April 21st 06 04:46 PM
Macro Date Manipulation DKY[_99_] Excel Programming 13 February 27th 06 07:45 PM
For better Performance in VBA for Excel - Strings manipulation OR Objects manipulation vmegha Excel Programming 2 December 19th 05 12:14 AM
Generating Code in Excel / Macro Recorder Manipulation [email protected] Excel Programming 2 August 18th 05 03:31 PM


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