+ Reply to Thread
Results 1 to 4 of 4

Combine date and time

  1. #1
    Registered User
    Join Date
    06-13-2006
    Posts
    14

    Combine date and time

    I'm sure this have been asked before, however I have searched several different variations and can't seem to find the answer. I have 2 columns, one has a date and the other has a time. I have tried several ways of combining these 2 columns with no success. I'm fairly new when it comes to VBA code so sorry for the newbie question.
    Here is the code I'm currently trying to use. When I run the macro I get a runtime error 13, missmatch type.

    Please Login or Register  to view this content.
    I then tried this code just to see if I was making an error with the counter etc...
    Please Login or Register  to view this content.

  2. #2
    John Fuller
    Guest

    Re: Combine date and time

    Your code snippet works just fine. If you're trying to loop through
    all the rows, then i would suggest this (assuming you want the result
    to go into column A, and the date is in B and the time is in C):

    LastRow=Range("A65532").End(xlUp).Row
    For i = 1 to LastRow
    Cells(i,1).Value = Cells(i,2).Value + Cells(i,3).Value
    Next i
    BN-CD wrote:
    > I'm sure this have been asked before, however I have searched several
    > different variations and can't seem to find the answer. I have 2
    > columns, one has a date and the other has a time. I have tried several
    > ways of combining these 2 columns with no success. I'm fairly new when
    > it comes to VBA code so sorry for the newbie question.
    > Here is the code I'm currently trying to use. When I run the macro I
    > get a runtime error 13, missmatch type.
    >
    >
    > Code:
    > --------------------
    > LastRow = Range("A65532").End(xlUp).Row
    > LastValue = Range("F" & LastRow).Value2 + 1
    > counter = 2
    > Do Until counter = LastValue + 1
    > Range("T" & counter).Value2 = Range("I" & counter).Value2 + Range("K" & counter).Value2
    > counter = counter + 1
    > Loop
    > --------------------
    >
    > I then tried this code just to see if I was making an error with the
    > counter etc...
    >
    > Code:
    > --------------------
    > Range("T2").Value2 = Range("I2").Value2 + Range("K2").Value2
    > --------------------
    >
    >
    > --
    > BN-CD
    > ------------------------------------------------------------------------
    > BN-CD's Profile: http://www.excelforum.com/member.php...o&userid=35374
    > View this thread: http://www.excelforum.com/showthread...hreadid=573245



  3. #3
    Tom Ogilvy
    Guest

    RE: Combine date and time

    Sub CombineColumns()
    Dim rng as Range
    set rng = Range(cells(2,"I"),cells(rows.count,"I").End(xlup))
    rng.offset(0,11).formula = "=Sum(I2,k2)"
    rng.offset(0,11).Numberformat = "mm/dd/yyyy hh:mm"
    rng.offset(0,11).Formula = rng.offset(0,11).Value
    end Sub

    --
    regards,
    Tom Ogilvy


    "BN-CD" wrote:

    >
    > I'm sure this have been asked before, however I have searched several
    > different variations and can't seem to find the answer. I have 2
    > columns, one has a date and the other has a time. I have tried several
    > ways of combining these 2 columns with no success. I'm fairly new when
    > it comes to VBA code so sorry for the newbie question.
    > Here is the code I'm currently trying to use. When I run the macro I
    > get a runtime error 13, missmatch type.
    >
    >
    > Code:
    > --------------------
    > LastRow = Range("A65532").End(xlUp).Row
    > LastValue = Range("F" & LastRow).Value2 + 1
    > counter = 2
    > Do Until counter = LastValue + 1
    > Range("T" & counter).Value2 = Range("I" & counter).Value2 + Range("K" & counter).Value2
    > counter = counter + 1
    > Loop
    > --------------------
    >
    > I then tried this code just to see if I was making an error with the
    > counter etc...
    >
    > Code:
    > --------------------
    > Range("T2").Value2 = Range("I2").Value2 + Range("K2").Value2
    > --------------------
    >
    >
    > --
    > BN-CD
    > ------------------------------------------------------------------------
    > BN-CD's Profile: http://www.excelforum.com/member.php...o&userid=35374
    > View this thread: http://www.excelforum.com/showthread...hreadid=573245
    >
    >


  4. #4
    Registered User
    Join Date
    06-13-2006
    Posts
    14
    Thanks for the help! I'll give them a try.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1