Results 1 to 20 of 62

Thread: VBA Code to Match US Region to the State that is entered

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Regular
    Joined
    Dec 2016
    Posts
    29
    Location
    Using Pauls uploaded workbook add the states to column A on the Example sheet and run macro

    Sub abc()
     Dim i As Long
     Dim rng As Range, cell As Range
     With Worksheets("states")
        arr = .Range("a1").CurrentRegion.Value
     End With
     With Worksheets("Example")
        Set rng = .Range("a1", Cells(Rows.Count, "a").End(xlUp))
     End With
     With CreateObject("scripting.dictionary")
        For i = 1 To UBound(arr)
            .Item(arr(i, 1)) = arr(i, 2)
        Next
        For Each cell In rng
            If .exists(cell.Value) Then
                cell.Offset(, 1) = .Item(cell.Value)
            Else
                cell.Offset(, 1) = "Not Found"
            End If
        Next
     End With
    End Sub
    See attached workbook: StatesRegions (1).xlsm
    Last edited by mike7952; 01-23-2017 at 08:26 AM.

Posting Permissions

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