Solved

Fix Time conversion

Posted on 2012-03-09
2
292 Views
Last Modified: 2012-03-09
I need Experts help to fix the time conversion script. The script is used to add 8 hours (+8), however the date conversion was not properly updated. e.g cell A2:A4 should updated as 10-Mar, by right should be 9-Mar. I have copied the actual time before conversion at Column F and G for Experts perusal.

Hope Experts could help me to fix this.

Sub ConvertDateandTime()
Dim cel As Range
For Each cel In Range("A2:A" & Range("A2").End(xlDown).Row)
cel.Value = cel.Value + Int(cel.Offset(0, 1) + 8 / 24)
cel.Offset(0, 1) = cel.Offset(0, 1) + 8 / 24 - Int(cel.Offset(0, 1) + 8 / 24)
Next cel
Columns("B:B").Select
Selection.NumberFormat = "hh:mm"

End Sub

Open in new window

Convert-Time.xls
0
Comment
Question by:Billa7
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 37702925
Sub ConvertDateandTime()
Dim cel As Range
For Each cel In Range("A2:A" & Range("A2").End(xlDown).Row)
cel.Offset(0, 1).Value = cel.Offset(0, 1).Value - Int(cel.Offset(0, 1).Value)
cel.Value = cel.Value + Int(cel.Offset(0, 1) + 8 / 24)
cel.Offset(0, 1) = cel.Offset(0, 1) + 8 / 24 - Int(cel.Offset(0, 1) + 8 / 24)
Next cel
Columns("B:B").Select
Selection.NumberFormat = "hh:mm"
End Sub
0
 

Author Closing Comment

by:Billa7
ID: 37703072
Thanks a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question