#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default compare

I think I was not asking the right question on my earlier post

I usually have a cell with a value of
1 or 12* or 7*

However sometime I might have on like this
CE 13:00-22:00

I need to know how to look for this and if encountered then check th
difference between 13:00 and 22:00 to see if it is 8 hours o
greater

thanks in advance
Rod Taylo

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default compare

Rod,

'Assumes there is a single hyphen and
'a single space in cell if looking for time value.

'The code looks for a hyphen in cell text and if found
'then looks for the first space. It then converts
'the first 5 characters (after space) to a date and the
'last five characters in the cell to a date and
'subtracts one from the other...

'This code makes too many assumptions for me to be
'comfortable with it, but it will get you started.

'-----------------------
Sub FindTheDuration()
Dim lngSpace As Long
Dim strValue As String
Dim dteAmount As Date
Const STR_HYPHEN As String = "-"
Const STR_SPACE As String = " "

strValue = Range("D5").Value

If InStr(1, strValue, STR_HYPHEN, vbTextCompare) 0 Then

lngSpace = InStr(1, strValue, STR_SPACE, vbTextCompare) + 1
dteAmount = CDate(Right(strValue, 5)) - CDate(Mid(strValue, lngSpace, 5))

MsgBox CDbl(dteAmount) * 24
End If
End Sub
'-----------------------

Regards,
Jim Cone
San Francisco, CA

"rjtaylor " wrote in message
...
I think I was not asking the right question on my earlier post
I usually have a cell with a value of
1 or 12* or 7*
However sometime I might have on like this
CE 13:00-22:00
I need to know how to look for this and if encountered then check the
difference between 13:00 and 22:00 to see if it is 8 hours or
greater
thanks in advance
Rod Taylor



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default compare

Ro

tr
=IF(LEFT(A5,2)="CE", IF(HOUR(RIGHT(A5,5)-MID(A5,4,5))=8,"More","Less"),"whatever you do otherwise"

Ton

----- rjtaylor wrote: ----

I think I was not asking the right question on my earlier pos

I usually have a cell with a value of
1 or 12* or 7

However sometime I might have on like thi
CE 13:00-22:0

I need to know how to look for this and if encountered then check th
difference between 13:00 and 22:00 to see if it is 8 hours o
greate

thanks in advanc
Rod Taylo


--
Message posted from http://www.ExcelForum.com


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default compare

Thanks Jim That seems to work now I need to get it into my code
I dont understand the

MsgBox CDbl(dteAmount) * 24

So I added this to put the answer back into code

If CDbl(dteAmount) * 24 = 8 Then
MsgBox ("yes")
Else
MsgBox ("no")
End If

I also might play with the code you gave Tony thank

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare and sum LiAD Excel Worksheet Functions 1 September 29th 09 02:34 PM
Compare CribbsStyle Excel Worksheet Functions 8 November 4th 06 10:15 PM
How do I compare cells and if FALSE compare to next cell in EXCEL Cindie Excel Worksheet Functions 0 March 24th 06 05:29 PM
compare dansd Excel Worksheet Functions 1 December 21st 04 12:19 PM
compare data from one column with another and compare result to yet another Matt Williamson[_3_] Excel Programming 1 September 25th 03 08:54 PM


All times are GMT +1. The time now is 04:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"