ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combine date and time (https://www.excelbanter.com/excel-programming/370836-combine-date-time.html)

BN-CD[_5_]

Combine date and time
 

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
-------------------
Range("T2").Value2 = Range("I2").Value2 + Range("K2").Value
-------------------

--
BN-C
-----------------------------------------------------------------------
BN-CD's Profile: http://www.excelforum.com/member.php...fo&userid=3537
View this thread: http://www.excelforum.com/showthread.php?threadid=57324


John Fuller

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



Tom Ogilvy

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



BN-CD[_6_]

Combine date and time
 

Thanks for the help! I'll give them a try

--
BN-C
-----------------------------------------------------------------------
BN-CD's Profile: http://www.excelforum.com/member.php...fo&userid=3537
View this thread: http://www.excelforum.com/showthread.php?threadid=57324



All times are GMT +1. The time now is 03:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com