vba - Splitting Date/Time into 2 columns -
i have code outputs date , time column a, them separate (date in column a, time in column b). tried figure out recording macro , doing delimited process within excel, didn't work wanted.
mainly want know if possible, or should try alternative coding separate them begin with. in advance!
sub macro1() dim dtime date range("a:a").select selection.numberformat = "mm/dd/yyyy hh:mm:ss am/pm" range("a1").select set cell = [a1] dtime = "3/01/2013 12:00:00 am" "3/02/2013 11:55:00 pm" step "00:05" activecell.value = dtime activecell.offset(1, 0).select next dtime end sub
you can use format(expression,[format]) format values before putting in cell. see updated code below (feel free update formats see fit)
sub macro1() dim dtime date dim x integer x = 1 dtime = "3/01/2013 12:00:00 am" "3/02/2013 11:55:00 pm" step "00:05" ' sets date in cell of first column cells(x,1).value = format(dtime, "mm/dd/yyyy") ' sets time in cell of second column cells(x,2).value = format(dtime, "hh:mm:ss am/pm") x = x + 1 next dtime end sub
Comments
Post a Comment