Announcement

Collapse
No announcement yet.

USD $15: Macro to convert ID to text

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • USD $15: Macro to convert ID to text

    I have data that has an ID column, the first 3 digits corresponding to a building name. I want to be able to run a macro that will take the first 3 letters and then convert it to a column with a name of the buildimg. As you can see sometimes the first 2 digits are the same but the 3rd digit could be A, B, C, D or E.

    The sample sheet shows in columns A-C the data I get and columns F-I show how I would like the data to look after a macro run.

    Let me know if you need more info to build out the macro.
    Attached Files

  • #2
    1. Have you paid your 10% to OZGrid as required by the forum rules?
    2. What is the criteria to determine which building a particular ID is located? Sorry, but unable to read your mind on this issue.
    Alan

    Did you debug your code first? http://www.cpearson.com/excel/DebuggingVBA.aspx
    FORUM RULES----->http://www.ozgrid.com/forum/announcement.php?f=8

    If someone has helped you, say "thank you" by clicking on the Like Button.

    Comment


    • #3
      1) I hadn't but I have now.
      2) No problem, the first 3 digits will determine the building. Right now 01(A,B,C,D,E) and 02(A,B,C,D,E) are East, 03(A,B,C,D,E) is West and 04(A,B,C,D,E) is North. It may expand in the future but those are the current criteria. Let me know if that clears up the conversion.

      Comment


      • #4
        Here is your code:

        Code:
        Option Explicit
        
        Sub Bldg()
            Dim i As Long
            Dim lr As Long
            lr = Range("A" & Rows.Count).End(xlUp).Row
            For i = 2 To lr
                If Left(Range("C" & i), 2) = "02" Or Left(Range("C" & i), 2) = "01" Then
                    Range("D" & i) = "East"
                ElseIf Left(Range("C" & i), 2) = "03" Then
                    Range("D" & i) = "West"
                ElseIf Left(Range("C" & i), 2) = "04" Then
                    Range("D" & i) = "North"
                End If
            Next i
        
        End Sub
        I will PM you my email address and you can make PayPal payment for the 90% balance.
        Alan

        Did you debug your code first? http://www.cpearson.com/excel/DebuggingVBA.aspx
        FORUM RULES----->http://www.ozgrid.com/forum/announcement.php?f=8

        If someone has helped you, say "thank you" by clicking on the Like Button.

        Comment


        • #5
          Payment sent and thanks for your quick help!

          Comment

          Working...
          X