+ Reply to Thread
Results 1 to 9 of 9

Assign TimeZone depending on State Abbreviation

  1. #1
    Registered User
    Join Date
    09-08-2016
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    45

    Assign TimeZone depending on State Abbreviation

    Hello,

    I would like to have Column "P" (timezone) be set to either "Pacific", "Mountain", "Central", or "Eastern" depending on the value of Column "N" (State)

    If cell in column N = CA, column P = "Pacific"
    If cell in column N = AZ, column P = "Mountain"
    If cell in column N = NV, column P = "Pacific"
    If cell in column N = TX, column P = "Central"

    Any help would be greatly appreciated.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,963

    Re: Assign TimeZone depending on State Abbreviation

    You could do this with a formula.
    In column P
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by ByteMarks; 04-19-2021 at 07:05 PM.

  3. #3
    Registered User
    Join Date
    09-08-2016
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    45

    Re: Assign TimeZone depending on State Abbreviation

    Quote Originally Posted by ByteMarks View Post
    You could do this with a formula.
    In column P
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ByteMarks, thanks so much for the info. In this case I am running a Macro through Power Automate Desktop so it would be best to use VBA.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    Only for good readers using a smart worksheet a VBA demonstration to paste to the worksheet module :

    PHP Code: 
    Sub Demo1()
        
    With UsedRange.Columns
            
    .Item(16).Value2 Evaluate("CHOOSE(IFERROR(MATCH(""*""&" & .Item(14).Address _
                
    "&""*"",{""AZ"",""CA NV"",""TX""},0),4),""Mountain"",""Pacific"",""Central"","""")")
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    09-08-2016
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    45

    Re: Hi ! Try this !

    Thank you Marc,

    I tried it but it gives me an error message Run-time error '424': Object Required.

    I thought the solution was much simpler so I did not add a sample Excel file from the beginning but I have now attached it.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow For good readers only …


    As it well worked on my side, as I warned for smart worksheet (ok) so the issue is located 'between the chair and the screen' !
    Well read & apply at least the post #4 direction … According to your attachment a tiny optimization :

    PHP Code: 
    Sub Demo1r()
        
    With UsedRange.Rows("2:" UsedRange.Rows.Count).Columns
            
    .Item(16).Value2 Evaluate("CHOOSE(IFERROR(MATCH(""*""&" & .Item(14).Address _
                
    "&""*"",{""AZ"",""CA NV"",""TX""},0),4),""Mountain"",""Pacific"",""Central"","""")")
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Registered User
    Join Date
    09-08-2016
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    45

    Re: For good readers only …

    Quote Originally Posted by Marc L View Post

    As it well worked on my side, as I warned for smart worksheet (ok) so the issue is located 'between the chair and the screen' !
    Well read & apply at least the post #4 direction … According to your attachment a tiny optimization :

    PHP Code: 
    Sub Demo1r()
        
    With UsedRange.Rows("2:" UsedRange.Rows.Count).Columns
            
    .Item(16).Value2 Evaluate("CHOOSE(IFERROR(MATCH(""*""&" & .Item(14).Address _
                
    "&""*"",{""AZ"",""CA NV"",""TX""},0),4),""Mountain"",""Pacific"",""Central"","""")")
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Marc, I don't understand your 'between the chair and the screen' comment. If it is meant to be sarcastic, or the For Good Readers Only, I don' appreciate it. People don't come to this forum to feel belittled. Communication is also the responsibility of who is transmitting the information to make sure the message gets across.

    I hope I am wrong and is just a language barrier.

    Anyway, your sub did not work for me.

    For someone looking for a solution to this, I came up with the following while avoiding UsedRange which is unreliable based on ByteMarks (who was verfy helpful by the way) formula with null as an option in case another state pops up that is not in the options and I also changed the Sheet name since I just changed the Sheet name on the workbook:

    PHP Code: 

    Sub StateAb
    ()

        
    With Sheets("Sheet1")
        
    Set RngCol = .Range("N2", .Cells(Rows.Count1).End(xlUp))
        
    End With
        LastRow 
    RngCol.Rows.Count
        Range
    ("P2:P" LastRow 1).Value "=IFERROR(CHOOSE((RC[-2]=""CA"")+(RC[-2]=""AZ"")*2+(RC[-2]=""NV"")*3+(RC[-2]=""TX"")*4,""Pacific"",""Mountain"",""Pacific"",""Central""),"""")"

    End Sub 

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,879

    Re: Assign TimeZone depending on State Abbreviation

    @MarcL

    Administrative Note:

    Common courtesy is the order of the day. Avoid coarse language, personal attacks and inflammatory remarks. Any concerns should be about topics not people.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Assign TimeZone depending on State Abbreviation


    It was just a slight touch of humor, as the solution belongs to good readers …

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Total value that matches the state abbreviation using XLOOKUP and SUM
    By jsagolf in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-16-2020, 04:39 PM
  2. [SOLVED] Formula to change full state name to abbreviation
    By 47magic in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-25-2020, 05:55 PM
  3. Help with formula - pull state abbreviation out of string of text
    By algioia in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-10-2019, 01:14 PM
  4. City/ State/ Country to TimeZone conversion
    By vij8y in forum Excel General
    Replies: 3
    Last Post: 09-22-2014, 02:21 AM
  5. Replies: 4
    Last Post: 01-22-2011, 07:33 AM
  6. System Timezone detection and abbreviation
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2009, 04:24 PM
  7. [SOLVED] spell out state name from an abbreviation
    By julieb in forum Excel General
    Replies: 2
    Last Post: 05-19-2005, 01:06 PM

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