Combine date and time

  • Thread starter Thread starter BN-CD
  • Start date Start date
B

BN-CD

I'm sure this have been asked before, however I have searched severa
different variations and can't seem to find the answer. I have
columns, one has a date and the other has a time. I have tried severa
ways of combining these 2 columns with no success. I'm fairly new whe
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
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
Loo
-------------------

I then tried this code just to see if I was making an error with th
counter etc...

Code
 
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
 
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
 

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

Similar Threads

Is ther a better way? 3
Loop without Do 2
Simple IF give me nothing? 2
code help 0
How to properly read Value2 Range ? 5
Run Time Error 1004 7
Counter stops working 4
help with a piece of code 5

Back
Top