#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Dates in VBA

I'm trying to do something very simple in Visual Basic, but am having
trouble.

All I want to do is put a date in a certain cell, based on a date in a
different cell on a different sheet.

The formula I would use if it weren't visual basic is:

=DATE(Year(Info!G2),Month(Info!G2),1)

How can I do this using visual basic?

Thanks!
Brett

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Dates in VBA

dim myCell as range
set mycell = worksheets("info").range("G2")

with activecell
.numberformat = "mm/dd/yyyy"
.value = dateserial(year(mycell.value), month(mycell.value), 1)
end with



wrote:

I'm trying to do something very simple in Visual Basic, but am having
trouble.

All I want to do is put a date in a certain cell, based on a date in a
different cell on a different sheet.

The formula I would use if it weren't visual basic is:

=DATE(Year(Info!G2),Month(Info!G2),1)

How can I do this using visual basic?

Thanks!
Brett


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Dates in VBA

info!G2 === Worksheets("Info").Range("G2") in VBA

Range("a1") = DateSerial(Year(Worksheets("Info").Range("G2")),
Month(Worksheets("Info").Range("G2")), 1)

" wrote:

I'm trying to do something very simple in Visual Basic, but am having
trouble.

All I want to do is put a date in a certain cell, based on a date in a
different cell on a different sheet.

The formula I would use if it weren't visual basic is:

=DATE(Year(Info!G2),Month(Info!G2),1)

How can I do this using visual basic?

Thanks!
Brett


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Dates in VBA

That did it! Thanks a lot!

Dave Peterson wrote:
dim myCell as range
set mycell = worksheets("info").range("G2")

with activecell
.numberformat = "mm/dd/yyyy"
.value = dateserial(year(mycell.value), month(mycell.value), 1)
end with



wrote:

I'm trying to do something very simple in Visual Basic, but am having
trouble.

All I want to do is put a date in a certain cell, based on a date in a
different cell on a different sheet.

The formula I would use if it weren't visual basic is:

=DATE(Year(Info!G2),Month(Info!G2),1)

How can I do this using visual basic?

Thanks!
Brett


--

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
Dates showing are not what I type Mick New Users to Excel 5 July 6th 06 04:19 AM
Dates and Intervals Dave_Lee Excel Worksheet Functions 8 May 26th 06 01:34 PM
formula to add dates. S S Excel Worksheet Functions 8 April 5th 06 07:53 PM
need to convert list of dates to count no. of dates by week neowok Excel Worksheet Functions 13 January 30th 06 03:54 PM
Calculating number of days between two dates that fall between two other dates [email protected] Excel Discussion (Misc queries) 5 October 26th 05 06:18 PM


All times are GMT +1. The time now is 06:26 AM.

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"