+ Reply to Thread
Results 1 to 6 of 6

VBA - How to "X" If "Y" is "This many" Characters long

  1. #1
    Registered User
    Join Date
    05-11-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question VBA - How to "X" If "Y" is "This many" Characters long

    Hi all,

    Long time fan, first time post. I'm a [BIG emphasis] complete beginner [/BIG emphasis] to VBA so I'd like to apologize in advanced for my ignorance. I hope this is a very simply issue. It is probaby out there in the interwebs, but I just haven't been able to find an answer... then again, I don't know exactly what I'm looking for, or how to phrase it.

    I'm (probably recreating the wheel) trying to set up code to format mailing/property address information. But I'm having difficulties with the ZIP code portion. This is what I have so far:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    This is more or less what I'm trying to do:
    Please Login or Register  to view this content.
    I'm basically trying to run the Step2 Macro only when the transposed cell values are 5 numbers.

    Hopefully this makes sense! Again, I want to apologize for my ignorance.

    Thanks,

    -H-

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA - How to "X" If "Y" is "This many" Characters long

    -H-,

    Welcome to the forum!

    It looks like what you're trying to do is:

    Get the 5 right-most characters of a cell to get the zip code
    If that is a number, and it is 5 digits long, then remove the zip code from the cell

    Is that right? In that case, something like this should work:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    05-11-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA - How to "X" If "Y" is "This many" Characters long

    Thank you ~tiger,

    Sorry for the late reply. It took me a bit to figure out how to work out the code. But it was what I needed to get everything working. Here is what I ended up with:

    Please Login or Register  to view this content.
    Thank you again for the great help!

    I do have one more quesion, however. I noticed this works perfecty, except when the value leads with zero's, i.e. "00001". Do you have any suggestions?

    Also, can excel even read "00001" as numeric while retaining its leading zeros?

    Thanks again!

    -H-

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA - How to "X" If "Y" is "This many" Characters long

    -H-,

    Made a slight change, give this a try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-11-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA - How to "X" If "Y" is "This many" Characters long

    Thank you ~tiger,

    You were a great help with the very little to none information I provided! You answered my question (or lack thereof) perfectly.

    I still have someproblems between figuring out how to differentiate between unit #'s, but I believe that will be a question for a next post, once I figure what it is that I'm really trying to do.

    Thanks for your help!!!

    -H-

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA - How to "X" If "Y" is "This many" Characters long

    You're very welcome, and thank you for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1