Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default DOH!!!! I'm a BONEHEAD

please don't waste your time with this thread. bonehead
mistake. SORRY!!!!

-----Original Message-----
Function TrimZip(OrigVal)

If InStr(OrigVal, "-") Then

OrigVal = Left(OrigVal, (Len(OrigVal) - InStr
(OrigVal, "-")))

End If

End Function

when i use it in my worksheet, i get 0 (zero) instead of

a
trimmed zip code.

supposed to work like this.....if it finds something like:

33534-0098, it will trim it down to 33534.

any ideas? thanks in advance!!!
.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default DOH!!!! I'm a BONEHEAD

Josh,

Actually - it's been a good exercise understanding InStr(), and catching all
the ins-n-outs of getting code to work.

My approach (for what it's worth) would have been dependent on length

If Len(OrigVal) = 0 Then
OrigVal = 0
ElseIf Len(OrigVal) 5 Then
OrigVal = Left(OrigVal,5)
Else
OrigVal = OrigVal
End If

Of couse you might want to check that the final OrigVal is numeric...
--
sb
"Josh in Tampa" wrote in message
...
please don't waste your time with this thread. bonehead
mistake. SORRY!!!!

-----Original Message-----
Function TrimZip(OrigVal)

If InStr(OrigVal, "-") Then

OrigVal = Left(OrigVal, (Len(OrigVal) - InStr
(OrigVal, "-")))

End If

End Function

when i use it in my worksheet, i get 0 (zero) instead of

a
trimmed zip code.

supposed to work like this.....if it finds something like:

33534-0098, it will trim it down to 33534.

any ideas? thanks in advance!!!
.



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default DOH!!!! I'm a BONEHEAD

sb:

this was what i came up with.....

Function TrimZip(OrigVal As Variant) As String

' check for blank entry
If Len(OrigVal) + 1 = 1 Then

' if empty, leave empty
TrimZip = OrigVal

Else

' check for zip code in which dash was
intended, but forgotten
If Len(OrigVal) = 9 And Not InStr(OrigVal, "-
") Then

' trim zip code to 5 digits
TrimZip = Left(OrigVal, 5)

' for all other zip code formats
Else

' trim zip code to 5 digits if a dash
exists
TrimZip = Split(OrigVal, "-")(0)

End If

End If

End Function


-----Original Message-----
Josh,

Actually - it's been a good exercise understanding InStr

(), and catching all
the ins-n-outs of getting code to work.

My approach (for what it's worth) would have been

dependent on length

If Len(OrigVal) = 0 Then
OrigVal = 0
ElseIf Len(OrigVal) 5 Then
OrigVal = Left(OrigVal,5)
Else
OrigVal = OrigVal
End If

Of couse you might want to check that the final OrigVal

is numeric...
--
sb
"Josh in Tampa"

wrote in message
...
please don't waste your time with this thread. bonehead
mistake. SORRY!!!!

-----Original Message-----
Function TrimZip(OrigVal)

If InStr(OrigVal, "-") Then

OrigVal = Left(OrigVal, (Len(OrigVal) - InStr
(OrigVal, "-")))

End If

End Function

when i use it in my worksheet, i get 0 (zero) instead

of
a
trimmed zip code.

supposed to work like this.....if it finds something

like:

33534-0098, it will trim it down to 33534.

any ideas? thanks in advance!!!
.



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default DOH!!!! I'm a BONEHEAD

Works for me...

Some thoughts:
to leave the cell blank:
TrimZip = ""
why check for "-"? Aren't you only concerned if Len 5

I just believe in brevity...
--
sb
wrote in message
...
sb:

this was what i came up with.....

Function TrimZip(OrigVal As Variant) As String

' check for blank entry
If Len(OrigVal) + 1 = 1 Then

' if empty, leave empty
TrimZip = OrigVal

Else

' check for zip code in which dash was
intended, but forgotten
If Len(OrigVal) = 9 And Not InStr(OrigVal, "-
") Then

' trim zip code to 5 digits
TrimZip = Left(OrigVal, 5)

' for all other zip code formats
Else

' trim zip code to 5 digits if a dash
exists
TrimZip = Split(OrigVal, "-")(0)

End If

End If

End Function


-----Original Message-----
Josh,

Actually - it's been a good exercise understanding InStr

(), and catching all
the ins-n-outs of getting code to work.

My approach (for what it's worth) would have been

dependent on length

If Len(OrigVal) = 0 Then
OrigVal = 0
ElseIf Len(OrigVal) 5 Then
OrigVal = Left(OrigVal,5)
Else
OrigVal = OrigVal
End If

Of couse you might want to check that the final OrigVal

is numeric...
--
sb
"Josh in Tampa"

wrote in message
...
please don't waste your time with this thread. bonehead
mistake. SORRY!!!!

-----Original Message-----
Function TrimZip(OrigVal)

If InStr(OrigVal, "-") Then

OrigVal = Left(OrigVal, (Len(OrigVal) - InStr
(OrigVal, "-")))

End If

End Function

when i use it in my worksheet, i get 0 (zero) instead

of
a
trimmed zip code.

supposed to work like this.....if it finds something

like:

33534-0098, it will trim it down to 33534.

any ideas? thanks in advance!!!
.



.



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



All times are GMT +1. The time now is 03:41 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"