Consulting

Results 1 to 8 of 8

Thread: Solved: Apply code only to column A

  1. #1

    Solved: Apply code only to column A

    Can someone assist in applying this code to only column A. Thanks

    [VBA]Sub Abbreviation2States()
    Dim c As Range
    For Each c In ActiveSheet.UsedRange
    Select Case UCase(c)
    Case "AL"
    c = "Alabama"
    Case "AZ"
    c = "Arizona"
    Case "AR"
    c = "Arkansas"
    Case "CA"
    c = "California"
    Case "CO"
    c = "Colorado"
    Case "CT"
    c = "Connecticut"
    Case "DE"
    c = "Delaware"
    Case "DC"
    c = "DISTRICT OF COLUMBIA"
    Case "FL"
    c = "Florida"
    Case "GA"
    c = "Georgia"
    Case "ID"
    c = "Idaho"
    Case "IL"
    c = "Illinois"
    Case "IN"
    c = "Indiana"
    Case "IA"
    c = "Iowa"
    Case "KS"
    c = "Kansas"
    Case "KY"
    c = "Kentucky"
    Case "LA"
    c = "Louisiana"
    Case "ME"
    c = "Maine"
    Case "MD"
    c = "Maryland"
    Case "MA"
    c = "Massachusetts"
    Case "MI"
    c = "Michigan"
    Case "MN"
    c = "Minnesota"
    Case "MS"
    c = "Mississippi"
    Case "MO"
    c = "Missouri"
    Case "MT"
    c = "Montana"
    Case "NE"
    c = "Nebraska"
    Case "NV"
    c = "Nevada"
    Case "NH"
    c = "New Hampshire"
    Case "NJ"
    c = "New Jersey"
    Case "NM"
    c = "New Mexico"
    Case "NY"
    c = "New York"
    Case "NC"
    c = "North Carolina"
    Case "ND"
    c = "North Dakota"
    Case "OH"
    c = "Ohio"
    Case "OK"
    c = "Oklahoma"
    Case "OR"
    c = "Oregon"
    Case "PA"
    c = "Pennsylvania"
    Case "RI"
    c = "Rhode Island"
    Case "SC"
    c = "South Carolina"
    Case "SD"
    c = "South Dakota"
    Case "TN"
    c = "Tennessee"
    Case "TX"
    c = "Texas"
    Case "UT"
    c = "Utah"
    Case "VT"
    c = "Vermont"
    Case "VA"
    c = "Virginia"
    Case "WA"
    c = "Washington"
    Case "WV"
    c = "West Virginia"
    Case "WI"
    c = "Wisconsin"
    Case "WY"
    c = "Wyoming"
    End Select
    Next c
    End Sub[/VBA]

  2. #2
    I found the answer...

    For Each c In ActiveSheet.Range("A:A")

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    That is an answer but is it efficient?

    Try:
    [VBA]For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))[/VBA]

  4. #4
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    So, what happened to Alaska and Hawaii, don't they count as states?
    Ron
    Windermere, FL

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Quote Originally Posted by Kenneth Hobs
    [vba]For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))[/vba]
    Is there a move on to add some more states Ron, that we don't know about?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Quote Originally Posted by Aussiebear
    Is there a move on to add some more states Ron, that we don't know about?
    G'day, Aussiebear,

    I do hope that you're pulling my leg.

    Alaska joined the Union on Jan 3, 1959, and Hawaii followed on Aug 21, 1959.

    The citizens of Puerto Rico, in a recent referendum, declined to apply for statehood. Another possible 51st state is our D.C. (District of Columbia, separate from Virginia and Maryland which surround it), analogous to your Australian Capital Territory. And, when I look at wikipedia I see that there are a bunch of other contenders, none of which are likely to become States any time soon.
    Ron
    Windermere, FL

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Aussiebear
    Is there a move on to add some more states Ron, that we don't know about?
    And what do you suppose is in ColumnA? Granted, one wonders why Alaska & Hawaii aren't included (maybe because they're not part of the contiguous States), but for all we know ColumnA has addresses with State abbreviations and the code is to return the State names for those abbreviations (of which there may only be a few or there may be thousands).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    yes Ron, just pulling your chain a wee bit....
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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