如何将数据整理成表格(方法二)
1、通过编写运行VBA代码,可以将复杂的数据,整理成很直观的表格!
2、在工作表中,点击菜单栏【开发工具】,在其工具栏内,点击【visual basic】!
3、进入VBA编辑界面!点击菜单栏【插入】,在其下拉菜单中,选择【模块】!
4、会弹出模块编辑窗口!
5、在代码编辑窗口输入以下代码:Sub test1()Set regx = CreateObject("稆糨孝汶;vbscript.regexp")With regx .Global = True .Pattern = "(\S+) (\S+) (\S) (\d+)(( \S+){1,3})" Set mat = .Execute(Sheet3.[a1]) For i = 0 To mat.Count - 1 Cells(i + 2, 1) = mat(i).SubMatches(0) Cells(i + 2, 2) = mat(i).SubMatches(1) Cells(i + 2, 3) = mat(i).SubMatches(2) Cells(i + 2, 4) = mat(i).SubMatches(3) Cells(i + 2, 5) = mat(i).SubMatches(4) NextEnd WithEnd Sub
6、与上篇经验代码的不同之处是: 掂迎豢畦For i = 0 To mat.Count - 1 Cells(i + 2, 1) = mat(i).SubMatches(0) Cells(i + 2, 2) = mat(i).SubMatches(1) Cells(i + 2, 3) = mat(i).SubMatches(2) Cells(i + 2, 4) = mat(i).SubMatches(3) Cells(i + 2, 5) = mat(i).SubMatches(4) Next利用了“mat”的不同属性!
7、点击工具栏中的【运行】按钮!
8、复杂的数据很快被整理成表格!