|
-
Jun 15th, 2006, 01:15 PM
#1
Thread Starter
Member
Leading zeros
I'm in a pickle so I come seeking the experts! 
I have a range of data that contains cells that report time in hours mins and seconds. If the amount of time is in seconds only, it's reporting as :00 and causing me problems when I lookup to it...specificially it returns nothing. My formulas use iserror so prevent errors showing up.
What I need is a script or macro that searches the range (a1:z20) and finds all cells there the leftmost char is a colon and replaces it with 0:
Any help on this would be greatly appreciated. (I do 30 pages of this a day and need a faster way to go through them)
-
Jun 15th, 2006, 01:36 PM
#2
Member
Re: Leading zeros
The way I understand it, you could do something like this:
VB Code:
If Left(Cells(row, column).value, 1) = ":" then
Cells(row, column).value = "0" + Cells(row, column)
Stick that in a loop, and you should be good.
-
Jun 15th, 2006, 01:47 PM
#3
Re: Leading zeros
Are you storing the time as a string or as a number?
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 15th, 2006, 02:18 PM
#4
Thread Starter
Member
Re: Leading zeros
as a number is what I'm trying to do. Java, you said to stick it in a loop. Can I ask you to show me how to do a loop as I've never done one successfully?
-
Jun 15th, 2006, 02:20 PM
#5
Member
Re: Leading zeros
Sure.
VB Code:
For i = startingNumber To endingNumber
If Left(Cells(row, column).value, 1) = ":" then
Cells(row, column).value = "0" + Cells(row, column)
End if
Next i
-
Jun 15th, 2006, 02:26 PM
#6
Re: Leading zeros
OK, that is not going to work if you are storing values
VB Code:
For i = startingNumber To endingNumber
If Left(Cells(row, column).value, 1) = ":" then
Cells(row, column).value = "0" + Cells(row, column)
End if
Next i
. The value of the cell doesn't contain a colon, that only in the format. To find cells that only have seconds you need to look for a cell value less than 0.00069444
(A day [24 Hrs] = 1.0 therefore 1 min = 0.00069444)
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 15th, 2006, 02:28 PM
#7
Member
Re: Leading zeros
Are you sure? Because I tested it before I posted, and it worked fine for me.
-
Jun 15th, 2006, 02:30 PM
#8
Re: Leading zeros
It will work if you are storig a Text String, not if you are storing a datetime value.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 15th, 2006, 02:36 PM
#9
Member
Re: Leading zeros
Well, that's depressing...sorry about that.
-
Jun 26th, 2006, 02:09 PM
#10
Thread Starter
Member
Re: Leading zeros
Sorry for the delay. been on a wee bit of a tear. I'll give it a whack tomorrow morning at work and see the magic.
Thank you both for your help! This place is a godsend!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|