从字典中提取数据

时间:2019-10-26 17:27:47

标签: excel vba

我的数据库有100列,其中A列是员工ID的唯一列表,K列是每位员工的薪水状态(免税,按小时,不免税等)。如何提取具有“豁免”状态(来自K列)的员工ID列表(来自A列)-请使用词典!换句话说,如何在下面的代码中继续执行步骤2?

Public Sub ExtractEmployeePayStatus()
      Dim i As Integer
      Dim p As Integer
      Dim cell As Range

      Dim rangeData1 As Range
      Dim rangeData2 As Range

      Dim rangePerform1 As Range
      Dim rangePerform2 As Range

      Dim dictionaryData1 As Scripting.Dictionary
      Dim dictionaryData2 As Scripting.Dictionary

      Dim strValue1 As String
      Dim strValue2 As String

      Dim w As Variant
      Dim v As Variant


      '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   Step 1 = Load employee numbers (unique list in column A)
      Set rangeData1 = Sheets("Database").Range("A9:A2008")
      Set dictionaryData1 = New Scripting.Dictionary
      dictionaryData1.CompareMode = TextCompare

      With rangeData1
            For Each cell In rangeData1.Columns(1).Cells
                  i = i + 1
                  strValue1 = cell.Text
                  If Not dictionaryData1.Exists(strValue1) Then
                        dictionaryData1.Add strValue1, .Rows(i)
                  Else
                        Set rangePerform1 = Union(.Rows(i), dictionaryData1(strValue1))
                        dictionaryData1.Remove strValue1
                        dictionaryData1.Add strValue1, rangePerform1
                  End If
            Next cell
      End With

      p = -1
      For Each w In dictionaryData1.Keys
         p = p + 1
         Debug.Print dictionaryData1.Keys(p)  '<<<<Possible to print related column K values???
      Next w

      '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   Step 2 = Load employment status (not unique list in column K)
            '''''How to load this????  How to do Step 2???


      '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   Step 3 = Compare Step 1 result vs Step 2 result
            ''''' I want to use dictionary per above to extract employee IDs (from column A) whose status is "Exempt" (from column K).
            ''''' I want to use dictionary because I have 10,000 employee IDs.  Dictionary will go faster.

End Sub

0 个答案:

没有答案