Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2008

Tip: Looking for answers? Try searching our database.

RIGHT & UPPER Function help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
roger lewis - 09 Mar 2008 11:55 GMT
I am working in Excel 2002.  The postal address is in cell A1 with the
postcode.  I am looking to take the postcode out of the cell and put in new
cell and turn into CAPITAL letters.
1 The High Street London ln22 4tb
I am struggling with the function for this.  I am at =RIGHT(A1,8)   which
takes the postcode from the end of the address and enters ino cell A2 but I
thought i may have been able to add the UPPER to the end of the function but
this does not work. I can do this as =UPPER(A2) in cell A3 but was hoping to
undertake the augument in the same cell.  Also can I adapt the augument to
include where I only have 6 characters ie LN24tb?

Many thanks

Roger
Gary''s Student - 09 Mar 2008 12:21 GMT
Hi Roger:

The first question is quite easy, just nest the functions:

=UPPER(RIGHT(A1,8))

The second question is not as easy.

Signature

Gary''s Student - gsnu2007e

>  I am working in Excel 2002.  The postal address is in cell A1 with the
> postcode.  I am looking to take the postcode out of the cell and put in new
[quoted text clipped - 10 lines]
>
> Roger
roger lewis - 09 Mar 2008 13:56 GMT
Thanks Gary I was nearly there.  Works ok now on first part.  Is the second
part undoable?

Regards

Roger
> Hi Roger:
>
[quoted text clipped - 24 lines]
>>
>> Roger
Gary''s Student - 09 Mar 2008 14:35 GMT
The difficulty is determining how much of the string to grab.  Look at the
last six characters.  If they contain a blank, we want eight.  If they do not
contain a blank, then we want six:

=UPPER(IF(LEN(SUBSTITUTE(RIGHT(A1,6)," ",""))=6,RIGHT(A1,6),RIGHT(A1,8)))

As you see, this formula is more complex, but usable.
Signature

Gary''s Student - gsnu2007e

> Thanks Gary I was nearly there.  Works ok now on first part.  Is the second
> part undoable?
[quoted text clipped - 30 lines]
> >>
> >> Roger
Rick Rothstein (MVP - VB) - 09 Mar 2008 19:02 GMT
Although I am not from Great Britain, I am pretty sure the postal codes over
there can be of either of these formats... "ccc ccc" or "cccc ccc" where 'c'
stands for character (either digit or letter). If you will ultimately need
to cater to both of those formats (plus your case of no internal space),
then I think this formula will do that...

=IF(LEFT(RIGHT(A1,8))<>" ",IF(LEFT(RIGHT(A1,7))<>"
",RIGHT(A1,8),RIGHT(A1,6)),TRIM(RIGHT(A1,7)))

While you didn't ask for this functionality, if you would like to insert any
missing space characters, while still catering to the two possible formats
listed above (plus your case of no internal space), then I think this
formula will do that...

=TRIM(IF(LEFT(RIGHT(A28,8))<>" ",IF(LEFT(RIGHT(A28,7))<>"
",RIGHT(A28,8),SUBSTITUTE(RIGHT(A28,6),RIGHT(A28,3),"
"&RIGHT(A28,3))),SUBSTITUTE(RIGHT(A28,7),RIGHT(A28,3)," "&RIGHT(A28,3))))

Rick

> Thanks Gary I was nearly there.  Works ok now on first part.  Is the
> second part undoable?
[quoted text clipped - 29 lines]
>>>
>>> Roger
Rick Rothstein (MVP - VB) - 09 Mar 2008 19:18 GMT
I just noticed that on my newsreader the two formulas I posted were broke
apart at the space characters that should be between quote marks. I also
notice that I didn't adjust the cell reference for my second formula back to
A1 from the A28 cell I used for my testing. Here are the two formulas again,
but this time I have broken them apart so that the break points are not at
the space characters (and the second one adjusted for its cell reference)...

=IF(LEFT(RIGHT(A1,8))<>" ",IF(LEFT(RIGHT(A1,7))
<>" ",RIGHT(A1,8),RIGHT(A1,6)),TRIM(RIGHT(A1,7)))

=TRIM(IF(LEFT(RIGHT(A1,8))<>" ",IF(LEFT(RIGHT
(A1,7))<>" ",RIGHT(A1,8),SUBSTITUTE(RIGHT(A1,6),
RIGHT(A1,3)," "&RIGHT(A1,3))),SUBSTITUTE(RIGHT
(A1,7),RIGHT(A1,3)," "&RIGHT(A1,3))))

Rick

> Although I am not from Great Britain, I am pretty sure the postal codes
> over there can be of either of these formats... "ccc ccc" or "cccc ccc"
[quoted text clipped - 50 lines]
>>>>
>>>> Roger
Ron Rosenfeld - 09 Mar 2008 21:09 GMT
On Sun, 9 Mar 2008 14:02:47 -0400, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.SPAM@NO.SPAMverizon.net> wrote:

>=TRIM(IF(LEFT(RIGHT(A28,8))<>" ",IF(LEFT(RIGHT(A28,7))<>"
>",RIGHT(A28,8),SUBSTITUTE(RIGHT(A28,6),RIGHT(A28,3),"
>"&RIGHT(A28,3))),SUBSTITUTE(RIGHT(A28,7),RIGHT(A28,3)," "&RIGHT(A28,3))))

Using this formula on:

1 the high street london A33AB

I get as a result:

on A33AB

--ron
Rick Rothstein (MVP - VB) - 09 Mar 2008 21:23 GMT
I guess we could build in some error checking for mistyping, but a
5-character string of text cannot be a postal code... I simply assumed all
entries had legitimate postal codes at the end.

Rick

> On Sun, 9 Mar 2008 14:02:47 -0400, "Rick Rothstein \(MVP - VB\)"
> <rick.newsNO.SPAM@NO.SPAMverizon.net> wrote:
[quoted text clipped - 12 lines]
>
> --ron
Ron Rosenfeld - 09 Mar 2008 21:35 GMT
On Sun, 9 Mar 2008 16:23:41 -0400, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.SPAM@NO.SPAMverizon.net> wrote:

>I guess we could build in some error checking for mistyping, but a
>5-character string of text cannot be a postal code... I simply assumed all
>entries had legitimate postal codes at the end.

Well, in his example he presented a postal code that did not have an included
space.  If we are going to allow for the absence of the space, then a five
character postal code, for GB, is possible, and it would be in the format of
ANNAA (where A is a letter of the alphabet, and N a number).

Here is a valid GB address:

10B Barry Jackson Tower
Estone Walk
BIRMINGHAM
B6 5BA
UNITED KINGDOM

Note that if the postal code were missing the <space>, it would be only five
characters.
--ron
Rick Rothstein (MVP - VB) - 09 Mar 2008 22:19 GMT
>>I guess we could build in some error checking for mistyping, but a
>>5-character string of text cannot be a postal code... I simply assumed all
[quoted text clipped - 18 lines]
> five
> characters.

Hmm! You are right... a "cc ccc" postal code is allowed (I missed that in my
check). Okay, I think this formula handles that situation...

=TRIM(IF(LEFT(RIGHT(A1,8))<>" ",IF(LEFT(RIGHT(A1,7))<>"
",IF(LEFT(RIGHT(A1,6))=" ",SUBSTITUTE(RIGHT(A1,5),RIGHT(A1,3),"
"&RIGHT(A1,3)),RIGHT(A1,8)),SUBSTITUTE(RIGHT(A1,6),RIGHT(A1,3),"
"&RIGHT(A1,3))),SUBSTITUTE(RIGHT(A1,7),RIGHT(A1,3)," "&RIGHT(A1,3))))

Note: I have not gone back to modify the first formula because I'm thinking
just preserving the same incorrect postal-code entry that the data contains
would not make sense; hence, I am suggesting the OP use the above formula
for his application (and not use the first one I posted at all since it
incorrectly handles the 5-character postal code you pointed out to me).

Rick
Ron Rosenfeld - 09 Mar 2008 22:52 GMT
On Sun, 9 Mar 2008 17:19:37 -0400, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.SPAM@NO.SPAMverizon.net> wrote:

>=TRIM(IF(LEFT(RIGHT(A1,8))<>" ",IF(LEFT(RIGHT(A1,7))<>"
>",IF(LEFT(RIGHT(A1,6))=" ",SUBSTITUTE(RIGHT(A1,5),RIGHT(A1,3),"
>"&RIGHT(A1,3)),RIGHT(A1,8)),SUBSTITUTE(RIGHT(A1,6),RIGHT(A1,3),"
>"&RIGHT(A1,3))),SUBSTITUTE(RIGHT(A1,7),RIGHT(A1,3)," "&RIGHT(A1,3))))

That does seem to work better.

It does still assume, however, that the ending of the line will always be a
valid post code (and also that there will not be any trailing spaces after the
post code).  But since the OP has not posted back with any more requirements,
it's probably not worthwhile to go further.

(Besides, I like my regex solution better <g>)

By the way, I still had to edit your formula in order to get it to work
properly, after pasting it in.  It inserted LF character in addition to a
<space>.

I suspect that is because, even though you may be "breaking" the lines in the
formula bar, you are entering the "breaks" within the quoted space.  So when I
paste it into my formula bar, <space><LF> gets inserted.

I would suggest breaking the lines outside of quoted text.

Yes, I know I suggested doing it that way, but I guess I've never entered the
breaks within quoted text :-(

--ron
Rick Rothstein (MVP - VB) - 09 Mar 2008 23:22 GMT
> (Besides, I like my regex solution better <g>)

LOL... but of course. <g>

> By the way, I still had to edit your formula in order to get it to work
> properly, after pasting it in.  It inserted LF character in addition to a
[quoted text clipped - 5 lines]
> when I
> paste it into my formula bar, <space><LF> gets inserted.

Isn't having to eat the LF standard for long formulas (or did I
misunderstand you)? As long as one leaves the spaces after the quote marks,
all should be well (providing it is realized the space is there, of
course<g>). Here is the formula broken apart so the breaks do not occur at a
space character...

=TRIM(IF(LEFT(RIGHT(A1,8))<>" ",IF(LEFT(RIGHT(A1,7))
<>" ",IF(LEFT(RIGHT(A1,6))=" ",SUBSTITUTE(RIGHT(A1,5),
RIGHT(A1,3)," "&RIGHT(A1,3)),RIGHT(A1,8)),SUBSTITUTE(
RIGHT(A1,6),RIGHT(A1,3)," "&RIGHT(A1,3))),SUBSTITUTE(
RIGHT(A1,7),RIGHT(A1,3)," "&RIGHT(A1,3))))

Rick
Ron Rosenfeld - 09 Mar 2008 23:58 GMT
On Sun, 9 Mar 2008 18:22:57 -0400, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.SPAM@NO.SPAMverizon.net> wrote:

>Isn't having to eat the LF standard for long formulas (or did I
>misunderstand you)? As long as one leaves the spaces after the quote marks,
[quoted text clipped - 9 lines]
>
>Rick

That one works fine.

I don't think I was specific about not putting the LF inside quotes.  If it's
not inside quotes, then everything works fine, though.
--ron
Dave Peterson - 09 Mar 2008 14:49 GMT
Maybe...

=UPPER(MID(RIGHT(A1,8),1,3))&RIGHT(A1,3)

But that depends on the final 8 characters always being the same format:
xxxx yyy

>  I am working in Excel 2002.  The postal address is in cell A1 with the
> postcode.  I am looking to take the postcode out of the cell and put in new
[quoted text clipped - 10 lines]
>
> Roger

Signature

Dave Peterson

Ron Rosenfeld - 09 Mar 2008 20:40 GMT
> I am working in Excel 2002.  The postal address is in cell A1 with the
>postcode.  I am looking to take the postcode out of the cell and put in new
[quoted text clipped - 10 lines]
>
>Roger

I thought it was a requirement that there be a <space> prior to the last 3
characters.

According to http://www.zipcodeworld.com/addressing/greatbritain.htm  valid
postcodes are in one of the following formats:

The postcode will be in one of the six following formats. 'A' represents a
letter of the alphabet and 'N' a digit:
    
Format         Example
AN NAA         M2 5BQ
ANN NAA     M34 4AB
AAN NAA     CR0 2YR
AANN NAA     DN16 9AA
ANA NAA     W1A 4ZZ
AANA NAA     EC1A 1HQ

Also, there are a finite number of postcode areas.

Depending on all of your requirements, it would be possible to at least ensure
that the postcode is valid; it would also be possible to insert a <space> if
one does not exist.

I would not want to develop a method to validate that the address and postcode
go together, however.  On that note I would point out that, according to the
above mentioned site, LN refers to Lincoln, UK and not London, UK.

So, do you want any type of validation?
Will some of your postcodes NOT have the required <space>?
Will some of your address lines NOT have postcodes at the end?

In any event, the User Defined Function below will extract anything that looks
similar to a valid postcode, with or without the required space, provided it is
at the end of a line of text.

It will return the result capitalized, and also with the last three characters
preceded by a <space>.

To enter this, <alt-F11> opens the VB Editor.  Ensure your project is
highlighted in the project explorer window, then Insert/Module and paste the
code below into the window that opens.  

If GB develops new postal areas, some modification of the code below will be
required, but that should be simple to do.

To use this, enter the formula =PostCode(cell_ref) where cell_ref refers to a
single cell.

This code should work even if the entire address is in a single cell.

====================================================
Option Explicit
Function PostCode(Str As String) As String
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
With re
   .Global = True
   .MultiLine = True
   .ignorecase = True
'Valid postcode format with optional <space>
   .Pattern = "(\b\w{1,2}\d\w?)\s?(\d[ABD-HJLNP-UW-Z]{2}\b)\s*$"
End With

If re.test(Str) = True Then
   Set mc = re.Execute(Str)
   PostCode = UCase(mc(0).submatches(0) _
       & " " & mc(0).submatches(1))
End If
End Function
===================================
--ron
roger lewis - 09 Mar 2008 23:03 GMT
Many thanks to you all for taking the time on a Sunday to resolving this
conundrum.  I will work my way through the replies and try and understand
them.

regards

Roger

>> I am working in Excel 2002.  The postal address is in cell A1 with the
>>postcode.  I am looking to take the postcode out of the cell and put in
[quoted text clipped - 97 lines]
> ===================================
> --ron

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.