如何在VBA中执行此任务?
示例,以下信息包含在Excel中名为fraca1的电子表格中,请注意字母A和F是Excel中的列名,而不是数据集的一部分。
A F
FRACA 012313 Correction 1
FRACA 012313 Correction 2
FRACA 012313 Investigation 1
FRACA 012313 Investigation 2
FRACA 012317 Investigation 1
FRACA 012317 Investigation 2
FRACA 012317 Investigation 3
FRACA 018593 Correction 1
FRACA 035586 Correction 1
我的数据包含在几个列中。我需要找到3件事。
然后,必须将此信息放入同一工作簿中的新电子表格中。生成的电子表格如下所示:
A B C
FRACA No. Correction No. Investigation No.
FRACA 012313 2 2
FRACA 012317 0 3
FRACA 018593 1 0
FRACA 035586 1 0
答案 0 :(得分:2)
我希望这会有所帮助,这是你问题的第一部分。您必须在VBA上激活Microsoft Scripting Runtime引用。
''''''''''''''''''
'1-What are the unique FRACA numbers in column A.
''''''''''''''''''
Application.Calculation = xlCalculationManual 'For faster running time
'Create the Scripting Dictionary
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim myFirstCol() As Variant
Dim i As Long
'Code Assumes data is in Sheet1 and needs to go to Sheet2 (code names)
arrLength = WorksheetFunction.CountA(Sheet1.Columns("A:A"))
ReDim myFirstCol(1 To arrLength)
'First read your input column
For i = 1 To arrLength
myFirstCol(i) = Sheet1.Cells(i, 1)
Next i
'create the unique keys
For i = LBound(myFirstCol) To UBound(myFirstCol)
d(myFirstCol(i)) = mySecondCol(i)
Next i
'Now write your keys to Sheet2
Dim v As Variant
i = 2
For Each v In d.Keys()
Sheet2.Cells(i, 1) = v
i = i + 1
Next v
Application.Calculation = xlCalculationAutomatic
对于您的其余问题,现在应该更容易解决FRACA的唯一值。如果我有一些时间,我将用其他两个部分完成答案。