Dates in VBA

  • Thread starter Thread starter brett.kaplan
  • Start date Start date
B

brett.kaplan

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
 
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
 
info!G2 ===> Worksheets("Info").Range("G2") in VBA

Range("a1") = DateSerial(Year(Worksheets("Info").Range("G2")),
Month(Worksheets("Info").Range("G2")), 1)
 
That did it! Thanks a lot!

Dave said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top