我正在将一些数据从txt文件导入excel
它看起来如何:
licence: MD2
approval: granted
id: 42FB1010C6B1ED82-0a292138.1
client: CH-W-7000361
username:asd
licence: CAI
approval: granted
id: 42FB1010C6B1ED82-0a292138.1
client: CH-W-7000361
username:qwe
因此它具有相同许可证但具有不同批准等的多个条目
我想要做的是:过滤数据并为其提供结构,使其看起来像:
有关我如何订购源数据的“规则”指南。只有许可证出现
它应该如何:
licence: EDR
approval: granted
client: pf-W-12365
approval: not granted
client: QT-B-7000361
client: C-S-7000361
我用数据透视表做了这个,但我想用宏
自动化它我的代码 我做了这个
Sub Order()
Dim dicKey As String
Dim dicValues As String
Dim dic
Dim data
data = Range("A1:D100") 'load data into variable
With CreatObject("scripting.dictionary")
For i = 1 To UBound(data)
If .Exists(data(i, 1)) Then 'test to see if the key exists
Else
dicKey = data(i, 1) 'set the Key
dicValues = data(i, 2) 'set the value for data to be stored
.Add dicKey, dicValues
End If
Next i
For Each dic In .Keys
If .Items(dic) <> "" Then
Debug.Print (dic)
'do stuff
End If
Next dic
End With
End Sub
答案 0 :(得分:0)
作为替代方案,我建议您使用 Power Query 加载文件。它是Microsoft提供的免费Add In,随Excel 2013和2016一起提供,可以免费下载到Excel 2010.
该工具可让您轻松设置自动查询以清理和整形数据。您可以拆分文本值,排序,过滤等。
它更加用户友好,并产生更可维护的结果。