VBA for Vlookup

时间:2014-11-21 21:25:21

标签: excel vba excel-vba

我是VBA菜鸟,我正在尝试在现有程序上编写vlookup,但我无法正常工作。

实施例: 如果来自A列的数字或文本与B列完全匹配,则继续执行该程序。如果不匹配,则停止程序仅运行该部分。

程序:

Sub BAT_Mobile()
    Dim S1LastRow
    Dim S1Range As Variant
    Dim S1Row As Variant

    Dim DefBuildingAbrev As Variant
    Dim DefUserPassword As Variant
    Dim DefUserLocale As Variant
    Dim DefUserPresGroup As Variant
    Dim DefUserCTICtrl As Variant
    Dim DefUserGrp1 As Variant
    Dim DefUserRemDestLim As Variant
    Dim DefUserMaxWaitPU As Variant
    Dim DefVoiceMailPrefix As Variant

    Dim S1CurrRow As Variant
    Dim S1CurrType As Variant
    Dim S1CurrTypeIPC As Variant
    Dim S1CurrDeviceName As String
    Dim S1CurrFirstName As Variant
    Dim S1CurrLastName As Variant
    Dim S1CurrCallerID As Variant
    Dim S1CurrFullName As Variant
    Dim S1CurrEmployeeID As Variant
    Dim S1CurrOff As Variant
    Dim S1CurrAgency As Variant
    Dim S1CurrBAC As Variant
    Dim S1CurrBuilding As Variant
    Dim S1CurrLocCode As Variant
    Dim S1CurrSLCount As Variant
    Dim S1CurrICCount As Variant
    Dim S1CurrDirNum1 As Variant
    Dim S1CurrDirNum2 As Variant
    Dim S1CurrDirNum2Name As Variant
    Dim S1CurrDirNum2Mask As Variant
    Dim S1CurrDirNum3 As Variant
    Dim S1CurrDirNum3Name As Variant
    Dim S1CurrDirNum3Mask As Variant
    Dim S1CurrDirNum4 As Variant
    Dim S1CurrDirNum4Name As Variant
    Dim S1CurrDirNum4Mask As Variant
    Dim S1CurrDirNum5 As Variant
    Dim S1CurrDirNum5Name As Variant
    Dim S1CurrDirNum5Mask As Variant
    Dim S1CurrDirNum6 As Variant
    Dim S1CurrDirNum6Name As Variant
    Dim S1CurrDirNum6Mask As Variant
    Dim S1CurrDirNum7 As Variant
    Dim S1CurrDirNum8 As Variant
    Dim S1CurrVoiceMailYN As Variant
    Dim S1CurrVoiceMailName As Variant
    Dim S1CurrExtMask1 As Variant
    Dim S1CurrDesc As Variant
    Dim S1CurrLineDesc As Variant
    Dim S1CurrLineText1 As Variant
    Dim S1CurrLineText2 As Variant
    Dim S1CurrLineText3 As Variant
    Dim S1CurrLineText4 As Variant
    Dim S1CurrLineText5 As Variant
    Dim S1CurrLineText6 As Variant
    Dim S1CurrICMYN As Variant
    Dim S1CurrICMDirNum As Variant


    Dim S1CurrDept As Variant

    Dim Phone6901RowCnt As Integer

    Dim Phone7906RowCnt As Integer
    Dim Phone7911RowCnt As Integer
    Dim Phone7937RowCnt As Integer

    Dim Phone784XRowCnt As Integer
    Dim Phone784X1L1SLRowCnt As Integer
    Dim Phone784X1L1ICRowCnt As Integer
    Dim Phone784X1LICMLRowCnt As Integer
    Dim Phone784X1LICM2LRowCnt As Integer

    Dim Phone784X3LRowCnt As Integer
    Dim Phone784X4LRowCnt As Integer

    Dim Phone796XRowCnt As Integer
    Dim Phone796X2LRowCnt As Integer
    Dim Phone796X3LRowCnt As Integer
    Dim Phone796X4LRowCnt As Integer
    Dim Phone796X5LRowCnt As Integer
    Dim Phone796X6LRowCnt As Integer

    Dim Phone796X1L1ICMRowCnt As Integer

    Dim Phone797XRowCnt As Integer
    Dim Phone797X1L1ICRowCnt As Integer

    Dim Phone784XINCRowCnt As Integer
    Dim Phone796XINCRowCnt As Integer
    Dim Phone797XINCRowCnt As Integer
    Dim PhoneIPCRowCnt As Integer
    Dim UserRowCnt As Integer
    Dim DummyVoiceMailCnt As Variant
    Dim DummyVoiceMailZeros As String
    Dim ICMCnt As Variant
    Dim ICMZeros As String
    Dim VoiceMailStdAKRowCnt As Integer
    Dim VoiceMailStdLZRowCnt As Integer
    Dim VoiceMailExcAKRowCnt As Integer
    Dim VoiceMailExcLZRowCnt As Integer
    Dim VoiceMailAdmAKRowCnt As Integer
    Dim VoiceMailAdmLZRowCnt As Integer

    Sheets("Defaults").Select
    DefBuildingAbrev = Trim(Sheets("Defaults").Range("B6").Value)
    DefUserPassword = Trim(Sheets("Defaults").Range("B8").Value)
    DefUserLocale = Trim(Sheets("Defaults").Range("B9").Value)
    DefUserPresGroup = Trim(Sheets("Defaults").Range("B10").Value)
    DefUserCTICtrl = Trim(Sheets("Defaults").Range("B11").Value)
    DefUserGrp1 = Trim(Sheets("Defaults").Range("B12").Value)
    DefUserRemDestLim = Trim(Sheets("Defaults").Range("B13").Value)
    DefUserMaxWaitPU = Trim(Sheets("Defaults").Range("B14").Value)
    DefVoiceMailPrefix = StrConv(Trim(Sheets("Defaults").Range("B16").Value), vbUpperCase)
    DummyVoiceMailCnt = Trim(Sheets("Defaults").Range("B17").Value)
    ICMCnt = Trim(Sheets("Defaults").Range("B19").Value)

    Phone6901RowCnt = 2

    Phone7906RowCnt = 2
    Phone7911RowCnt = 2
    Phone7937RowCnt = 2

    Phone784XRowCnt = 2
    Phone784X1L1SLRowCnt = 2
    Phone784X1L1ICRowCnt = 2
    Phone784X1LICMLRowCnt = 2
    Phone784X1LICM2LRowCnt = 2

    Phone784X3LRowCnt = 2
    Phone784X4LRowCnt = 2

    Phone796XRowCnt = 2
    Phone796X2LRowCnt = 2
    Phone796X3LRowCnt = 2
    Phone796X4LRowCnt = 2
    Phone796X5LRowCnt = 2
    Phone796X6LRowCnt = 2

    Phone796X1L1ICMRowCnt = 2

    Phone797XRowCnt = 2
    Phone797X1L1ICRowCnt = 2

    PhoneIPCRowCnt = 2
    UserRowCnt = 2
    VoiceMailStdAKRowCnt = 2
    VoiceMailStdLZRowCnt = 2
    VoiceMailExcAKRowCnt = 2
    VoiceMailExcLZRowCnt = 2
    VoiceMailAdmAKRowCnt = 2
    VoiceMailAdmLZRowCnt = 2

    'Finds Last row of Phone Database and sets the range
    Sheets("Phone_Database").Select
    S1LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set S1Range = Range("A2:FZ" & S1LastRow)


    'Goes through each row of Phone Database
    For Each S1Row In S1Range.Rows

    S1CurrRow = ""
    S1CurrType = ""
    S1CurrTypeIPC = ""
    S1CurrDeviceName = ""
    S1CurrFirstName = ""
    S1CurrLastName = ""
    S1CurrCallerID = ""
    S1CurrFullName = ""
    S1CurrEmployeeID = ""
    S1CurrOff = ""
    S1CurrAgency = ""
    S1CurrBAC = ""
    S1CurrBuilding = ""
    S1CurrLocCode = ""
    S1CurrSLCount = 0
    S1CurrICCount = 0
    S1CurrDirNum1 = ""
    S1CurrDirNum2 = ""
    S1CurrDirNum2Name = ""
    S1CurrDirNum2Mask = ""
    S1CurrDirNum3 = ""
    S1CurrDirNum3Name = ""
    S1CurrDirNum3Mask = ""
    S1CurrDirNum4 = ""
    S1CurrDirNum4Name = ""
    S1CurrDirNum4Mask = ""
    S1CurrDirNum5 = ""
    S1CurrDirNum5Name = ""
    S1CurrDirNum5Mask = ""
    S1CurrDirNum6 = ""
    S1CurrDirNum6Name = ""
    S1CurrDirNum6Mask = ""
    S1CurrDirNum7 = ""
    S1CurrDirNum8 = ""
    S1CurrVoiceMailYN = ""
    S1CurrVoiceMailName = ""
    DummyVoiceMailZeros = ""
    S1CurrExtMask1 = ""
    S1CurrDesc = ""
    S1CurrLineDesc = ""
    S1CurrLineText1 = ""
    S1CurrLineText2 = ""
    S1CurrLineText3 = ""
    S1CurrLineText4 = ""
    S1CurrLineText5 = ""
    S1CurrLineText6 = ""
    S1CurrICMYN = ""
    ICMZeros = ""
    S1CurrICMDirNum = ""
    S1CurrDept = ""

        S1CurrRow = S1Row.Row



        Sheets("Phone_Database").Select

        'BUILD VALUES
        'Figure Phone Type
        If Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "7841" Then
            S1CurrType = "7841"
        ElseIf Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "7965" Then
            S1CurrType = "7965"
        ElseIf Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "7975" Then
            S1CurrType = "7975"
        ElseIf Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "7911" Then
            S1CurrType = "7911"
        ElseIf Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "7906" Then
            S1CurrType = "7906"
        ElseIf Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "7937" Then
            S1CurrType = "7937"
        ElseIf Trim(Sheets("Phone_Database").Range("E" & S1CurrRow).Value) = "6901" Then
            S1CurrType = "6901"
        Else
            S1CurrType = ""
        End If



        'If Trim(Sheets("Phone_Database").Range("BC" & S1CurrRow).Value) <> "" Then
        '    S1CurrICMYN = "yes"
        'End If

        'Copy the mac address
        S1CurrDeviceName = StrConv(Trim(Sheets("Phone_Database").Range("A" & S1CurrRow).Value), vbUpperCase)
        'S1CurrDeviceName = Trim(Sheets("Phone_Database").Range("J" & S1CurrRow).Value)
        'Build the Name
        S1CurrFirstName = StrConv(Trim(Sheets("Phone_Database").Range("C" & S1CurrRow).Value), vbProperCase)
        S1CurrLastName = StrConv(Trim(Sheets("Phone_Database").Range("B" & S1CurrRow).Value), vbProperCase)
        S1CurrCallerID = Trim(Sheets("Phone_Database").Range("D" & S1CurrRow).Value)
        If Trim(S1CurrCallerID) <> "" Then
            S1CurrFullName = S1CurrCallerID
        Else
            S1CurrFullName = S1CurrFirstName & " " & S1CurrLastName
        End If
        'Build the Description
        S1CurrOff = Trim(Sheets("Phone_Database").Range("I" & S1CurrRow).Value)

        S1CurrAgency = Trim(Sheets("Phone_Database").Range("G" & S1CurrRow).Value)

        S1CurrBAC = Trim(Sheets("Phone_Database").Range("H" & S1CurrRow).Value)

        S1CurrBuilding = StrConv(Trim(Sheets("Phone_Database").Range("F" & S1CurrRow).Value), vbProperCase)

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrDesc = S1CurrBuilding & " " & S1CurrAgency & " Rm " & S1CurrOff & " " & S1CurrFullName & " " & S1CurrBAC
        Else
            S1CurrDesc = DefBuildingAbrev & " " & S1CurrAgency & " Rm " & S1CurrOff & " " & S1CurrFullName & " " & S1CurrBAC
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineDesc = S1CurrBuilding & " " & S1CurrAgency & " Rm " & S1CurrOff & " " & S1CurrFullName
        Else
            S1CurrLineDesc = DefBuildingAbrev & " " & S1CurrAgency & " Rm " & S1CurrOff & " " & S1CurrFullName
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineText1 = S1CurrFullName & " " & S1CurrDirNum1
        Else
            S1CurrLineText1 = S1CurrFullName & " " & S1CurrDirNum1
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineText2 = S1CurrFullName & " " & S1CurrDirNum2
        Else
            S1CurrLineText2 = S1CurrFullName & " " & S1CurrDirNum2
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineText3 = S1CurrFullName & " " & S1CurrDirNum3
        Else
            S1CurrLineText3 = S1CurrFullName & " " & S1CurrDirNum3
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineText4 = S1CurrFullName & " " & S1CurrDirNum4
        Else
            S1CurrLineText4 = S1CurrFullName & " " & S1CurrDirNum4
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineText5 = S1CurrFullName & " " & S1CurrDirNum5
        Else
            S1CurrLineText5 = S1CurrFullName & " " & S1CurrDirNum5
        End If

        If Trim(S1CurrBuilding) <> "" Then
            S1CurrLineText6 = S1CurrFullName & " " & S1CurrDirNum6
        Else
            S1CurrLineText6 = S1CurrFullName & " " & S1CurrDirNum6
        End If

        'Build Tie Line
        S1CurrLocCode = Application.Substitute(Trim(Sheets("Phone_Database").Range("Q" & S1CurrRow).Value), "8-", "")
        If Len(S1CurrLocCode) > 3 Then
            S1CurrLocCode = Right(S1CurrLocCode, 3)
        ElseIf Len(S1CurrLocCode) < 3 Then
            S1CurrLocCode = "FIXLOCCODE!"
        End If

         'Build UserID
        S1CurrEmployeeID = StrConv(Trim(Sheets("Phone_Database").Range("J" & S1CurrRow).Value), vbUpperCase)
        'Build External Phone Number Mask
        S1CurrExtMask1 = StrConv(Trim(Sheets("Phone_Database").Range("L" & S1CurrRow).Value), vbUpperCase)
        'S1CurrExtMask1 = Application.Substitute(Trim(Sheets("Phone_Database").Range("M" & S1CurrRow).Value), "-", "") & "XXXX"
        'Build Department
        S1CurrDept = Trim(Sheets("Phone_Database").Range("V" & S1CurrRow).Value)

        'Figure no. of Shared Lines
        If Trim(Sheets("Phone_Database").Range("P" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("T" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("X" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("AB" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("AF" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("BT" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("CA" & S1CurrRow).Value) = "shared" Then
            S1CurrSLCount = S1CurrSLCount + 1
        End If

        'Figure no. of Intercoms
        If Trim(Sheets("Phone_Database").Range("P" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("T" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("X" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("AB" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("AF" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("BT" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If
        If Trim(Sheets("Phone_Database").Range("CA" & S1CurrRow).Value) = "intercom" Then
            S1CurrICCount = S1CurrICCount + 1
        End If



        'Build First Dir Number
        'S1CurrDirNum1 = Application.Substitute(Trim(Sheets("Phone_Database").Range("K" & S1CurrRow).Value), "-", "")
        S1CurrDirNum1 = Trim(Sheets("Phone_Database").Range("K" & S1CurrRow).Value)
        If Len(S1CurrDirNum1) = 4 Then
            S1CurrDirNum1 = S1CurrLocCode & S1CurrDirNum1
        End If

        'Build Dir Num 2
        If Trim(Sheets("Phone_Database").Range("P" & S1CurrRow).Value) = "shared" Then
            S1CurrDirNum2 = Trim(Sheets("Phone_Database").Range("O" & S1CurrRow).Value)
            If Len(S1CurrDirNum2) = 4 Then
                S1CurrDirNum2 = S1CurrLocCode & S1CurrDirNum2
            End If
            S1CurrDirNum2Name = Trim(Sheets("Phone_Database").Range("R" & S1CurrRow).Value)
            If Trim(Sheets("Phone_Database").Range("R" & S1CurrRow).Value) = "" Then
                S1CurrDirNum2Mask = S1CurrExtMask1
            Else
                S1CurrDirNum2Mask = Trim(Sheets("Phone_Database").Range("Q" & S1CurrRow).Value)
            End If
        End If

        'Build Intercom Num 2
        If Trim(Sheets("Phone_Database").Range("P" & S1CurrRow).Value) = "intercom" Then
            S1CurrDirNum2 = Trim(Sheets("Phone_Database").Range("O" & S1CurrRow).Value)
            If Len(S1CurrDirNum2) = 4 Then
                S1CurrDirNum2 = S1CurrLocCode & S1CurrDirNum2
            End If
            S1CurrDirNum2Name = Trim(Sheets("Phone_Database").Range("R" & S1CurrRow).Value)
            If Trim(Sheets("Phone_Database").Range("R" & S1CurrRow).Value) = "" Then
                S1CurrDirNum3Mask = S1CurrExtMask1
            Else
                S1CurrDirNum3Mask = Trim(Sheets("Phone_Database").Range("Q" & S1CurrRow).Value)
            End If
        End If

        'Build Dir Num 3
        If Trim(Sheets("Phone_Database").Range("T" & S1CurrRow).Value) = "shared" Then
            S1CurrDirNum3 = Trim(Sheets("Phone_Database").Range("S" & S1CurrRow).Value)
            If Len(S1CurrDirNum3) = 4 Then
                S1CurrDirNum3 = S1CurrLocCode & S1CurrDirNum3
            End If
            S1CurrDirNum3Name = Trim(Sheets("Phone_Database").Range("V" & S1CurrRow).Value)
            If Trim(Sheets("Phone_Database").Range("V" & S1CurrRow).Value) = "" Then
                S1CurrDirNum3Mask = S1CurrExtMask1
            Else
                S1CurrDirNum3Mask = Trim(Sheets("Phone_Database").Range("U" & S1CurrRow).Value)
            End If
        End If

        'Build Dir Num 4
        If Trim(Sheets("Phone_Database").Range("X" & S1CurrRow).Value) = "shared" Then
            S1CurrDirNum4 = Trim(Sheets("Phone_Database").Range("W" & S1CurrRow).Value)
            If Len(S1CurrDirNum4) = 4 Then
                S1CurrDirNum4 = S1CurrLocCode & S1CurrDirNum4
            End If
            S1CurrDirNum4Name = Trim(Sheets("Phone_Database").Range("Z" & S1CurrRow).Value)
            If Trim(Sheets("Phone_Database").Range("Z" & S1CurrRow).Value) = "" Then
                S1CurrDirNum4Mask = S1CurrExtMask1
            Else
                S1CurrDirNum4Mask = Trim(Sheets("Phone_Database").Range("Y" & S1CurrRow).Value)
            End If
        End If

        'Build Dir Num 5
       If Trim(Sheets("Phone_Database").Range("AB" & S1CurrRow).Value) = "shared" Then
            S1CurrDirNum5 = Trim(Sheets("Phone_Database").Range("AA" & S1CurrRow).Value)
            If Len(S1CurrDirNum5) = 4 Then
                S1CurrDirNum5 = S1CurrLocCode & S1CurrDirNum5
            End If
            S1CurrDirNum4Name = Trim(Sheets("Phone_Database").Range("AD" & S1CurrRow).Value)
            If Trim(Sheets("Phone_Database").Range("AD" & S1CurrRow).Value) = "" Then
                S1CurrDirNum5Mask = S1CurrExtMask1
            Else
                S1CurrDirNum5Mask = Trim(Sheets("Phone_Database").Range("AC" & S1CurrRow).Value)
            End If
        End If

        'Build Dir Num 6
       If Trim(Sheets("Phone_Database").Range("AF" & S1CurrRow).Value) = "shared" Then
            S1CurrDirNum6 = Trim(Sheets("Phone_Database").Range("AE" & S1CurrRow).Value)
            If Len(S1CurrDirNum6) = 4 Then
                S1CurrDirNum6 = S1CurrLocCode & S1CurrDirNum6
            End If
            S1CurrDirNum6Name = Trim(Sheets("Phone_Database").Range("AH" & S1CurrRow).Value)
            If Trim(Sheets("Phone_Database").Range("AH" & S1CurrRow).Value) = "" Then
                S1CurrDirNum6Mask = S1CurrExtMask1
            Else
                S1CurrDirNum6Mask = Trim(Sheets("Phone_Database").Range("AG" & S1CurrRow).Value)
            End If
        End If

        'Build Dir Num 7
        S1CurrDirNum7 = Trim(Sheets("Phone_Database").Range("BZ" & S1CurrRow).Value)
        If Len(S1CurrDirNum7) = 4 Then
            S1CurrDirNum7 = S1CurrLocCode & S1CurrDirNum7
        Else
            S1CurrDirNum7 = ""
        End If
        'Build Dir Num 8
        S1CurrDirNum8 = Trim(Sheets("Phone_Database").Range("AO" & S1CurrRow).Value)
        If Len(S1CurrDirNum8) = 4 Then
            S1CurrDirNum8 = S1CurrLocCode & S1CurrDirNum8
        Else
            S1CurrDirNum8 = ""
        End If

        'Build Voicemail Boolean
        S1CurrVoiceMailYN = StrConv(Trim(Sheets("Phone_Database").Range("N" & S1CurrRow).Value), vbLowerCase)


        'PHONE
        If S1CurrDeviceName <> "" Then
          Select Case S1CurrType

          Case "6901"

            If S1CurrSLCount = 0 And S1CurrICCount = 0 Then
            'Paste the Device Name
            Sheets("6901").Select
            Sheets("6901").Range("A" & Phone6901RowCnt).Value = S1CurrDeviceName
            Sheets("6901").Range("B" & Phone6901RowCnt).Value = S1CurrDesc

            'Paste Dir Num 1 and Names and Mask
            Sheets("6901").Range("C" & Phone6901RowCnt).Value = S1CurrDirNum1
            Sheets("6901").Range("D" & Phone6901RowCnt).Value = "voicemail"
            Sheets("6901").Range("E" & Phone6901RowCnt).Value = S1CurrLineText1 & " - " & S1CurrDirNum1
            Sheets("6901").Range("F" & Phone6901RowCnt).Value = S1CurrLineDesc
            Sheets("6901").Range("G" & Phone6901RowCnt).Value = S1CurrFullName
            Sheets("6901").Range("H" & Phone6901RowCnt).Value = S1CurrFullName
            Sheets("6901").Range("I" & Phone6901RowCnt).Value = S1CurrFullName
            Sheets("6901").Range("J" & Phone6901RowCnt).Value = S1CurrFullName
            Sheets("6901").Range("K" & Phone6901RowCnt).Value = S1CurrLineText1 & " - " & S1CurrDirNum1
            Sheets("6901").Range("L" & Phone6901RowCnt).Value = S1CurrExtMask1

            Phone6901RowCnt = Phone6901RowCnt + 1
            End If

          Case "7841"

            If S1CurrSLCount = 0 And S1CurrICCount = 0 Then
            'Paste the Device Name
            Sheets("7841_L").Select
            Sheets("7841_L").Range("A" & Phone784XRowCnt).Value = S1CurrDeviceName
            Sheets("7841_L").Range("B" & Phone784XRowCnt).Value = S1CurrDesc

            'Paste Dir Num 1 and Names and Mask
            Sheets("7841_L").Range("C" & Phone784XRowCnt).Value = S1CurrDirNum1
            Sheets("7841_L").Range("D" & Phone784XRowCnt).Value = "voicemail"
            Sheets("7841_L").Range("E" & Phone784XRowCnt).Value = S1CurrLineText1 & " - " & S1CurrDirNum1
            Sheets("7841_L").Range("F" & Phone784XRowCnt).Value = S1CurrLineDesc
            Sheets("7841_L").Range("G" & Phone784XRowCnt).Value = S1CurrFullName
            Sheets("7841_L").Range("H" & Phone784XRowCnt).Value = S1CurrFullName
            Sheets("7841_L").Range("I" & Phone784XRowCnt).Value = S1CurrFullName
            Sheets("7841_L").Range("J" & Phone784XRowCnt).Value = S1CurrFullName
            Sheets("7841_L").Range("K" & Phone784XRowCnt).Value = S1CurrLineText1 & " - " & S1CurrDirNum1
            Sheets("7841_L").Range("L" & Phone784XRowCnt).Value = S1CurrExtMask1

            Phone784XRowCnt = Phone784XRowCnt + 1
            End If

            If S1CurrSLCount = 1 And S1CurrICCount = 0 Then
            'Paste the Device Name
            Sheets("7841_2L").Select
            Sheets("7841_2L").Range("A" & Phone784X1L1SLRowCnt).Value = S1CurrDeviceName
            Sheets("7841_2L").Range("B" & Phone784X1L1SLRowCnt).Value = S1CurrDesc
            'Paste Dir Num 1 and Names and Mask
            Sheets("7841_2L").Range("C" & Phone784X1L1SLRowCnt).Value = S1CurrDirNum1
            Sheets("7841_2L").Range("D" & Phone784X1L1SLRowCnt).Value = "voicemail"
            Sheets("7841_2L").Range("E" & Phone784X1L1SLRowCnt).Value = S1CurrLineText1 & " - " & S1CurrDirNum1
            Sheets("7841_2L").Range("F" & Phone784X1L1SLRowCnt).Value = S1CurrLineDesc
            Sheets("7841_2L").Range("G" & Phone784X1L1SLRowCnt).Value = S1CurrFullName
            Sheets("7841_2L").Range("H" & Phone784X1L1SLRowCnt).Value = S1CurrFullName
            Sheets("7841_2L").Range("I" & Phone784X1L1SLRowCnt).Value = S1CurrFullName
            Sheets("7841_2L").Range("J" & Phone784X1L1SLRowCnt).Value = S1CurrFullName
            Sheets("7841_2L").Range("K" & Phone784X1L1SLRowCnt).Value = S1CurrLineText1 & " - " & S1CurrDirNum1
            Sheets("7841_2L").Range("L" & Phone784X1L1SLRowCnt).Value = S1CurrExtMask1

            'Paste Shared Line
            Sheets("7841_2L").Range("M" & Phone784X1L1SLRowCnt).Value = S1CurrDirNum2
            Sheets("7841_2L").Range("N" & Phone784X1L1SLRowCnt).Value = S1CurrLineText2 & " - " & S1CurrDirNum2
            Sheets("7841_2L").Range("O" & Phone784X1L1SLRowCnt).Value = S1CurrDirNum2Name
            Sheets("7841_2L").Range("P" & Phone784X1L1SLRowCnt).Value = S1CurrDirNum2Name
            Sheets("7841_2L").Range("Q" & Phone784X1L1SLRowCnt).Value = S1CurrLineText2 & " - " & S1CurrDirNum2
            Sheets("7841_2L").Range("R" & Phone784X1L1SLRowCnt).Value = S1CurrDirNum2Mask


            Phone784X1L1SLRowCnt = Phone784X1L1SLRowCnt + 1
            End If

1 个答案:

答案 0 :(得分:3)

变种蝙蝠侠的圣墙!您需要投资For... Next循环。

LastRow = Range.("column letter" & Rows.Count).End(xlUp).Row 'Find the last row
For CurRow = 2 to LastRow 'Pick a starting row depending on headers
    If Cells(CurRow, COLUMN NUMBER "1").Value = Cells(CurRow, COLUMN NUMBER "2").Value Then
        'DO ALL YOUR FUN STUFF
    Else
    End If
Next CurRow