我正在为文件夹中的多个文本文件进行主题建模。我已经将最终的综合文本文件中的数据导入到excel中。它的格式如下。整数表示主题,小数表示该文本文件中发生该主题的百分比。将数据重新格式化为另一个Excel工作表
| C | | D | | E | | F | | G | | H | | I | | Ĵ |
| 2 | | 0.85 | | 1 | | 0.05 | | 0 | | 0.012 | | 3 | | 0.004 | ....
| 0 | | 0.50 | | 2 | | 0.31 | | 3 | | 0.146 | | 1 | | 0.068 | ...
主题编号需要成为列标题,并且百分比在下面。我需要将数据按以下格式重新格式化为另一张:
| D | | E | | F | | G |
| 0 | | 1 | | 2 | | | ... | n |
| 0.012 | | 0.05 | | 0.85 | | 0.004 |
| 0.50 | | 0.068 | | 0.31 | | 0.146 |
每个文本文件将具有相同的主题数量,但主题数量可能会有所不同。因此,这个例子有4个主题,但另一个可能有20,25等。我尝试使用items方法,但它看起来像我将不得不硬编码那里的值。有没有另一种方法来做到这一点?
下面是我的源数据的模样:
我试过,但一直被卡住:
Sub Items_Ex()
Dim myColumn As Long myRow = 2
While Worksheets("Input_Format_A").Cells(2, myColumn).Value <> ""
Dim myRow As Long myRow = 3
While Worksheets("Input_Format_A").Cells(myRow, 3).Value <> ""
Dim d As Dictionary Dim a, i 'Create some variables
Set d = New Dictionary
d.Add "1", Worksheets("Input_Text").Cells(1, 8).Value
d.Add "2", Worksheets("Input_Text").Cells(1, 6).Value
d.Add "3", Worksheets("Input_Text").Cells(1, 4).Value 'Do until there are no more topics
a = d.Items 'Get the items For i = 0 To d.Count - 1 'Iterate the array
Debug.Print a(i) 'Print item Next
Debug.Print d.Item("b")
myRow = myRow + 1
Wend
Wend
End Sub
你不介意跟我们至少相关一块分享努力 - 只是为了支持[你有什么尝试?](http://whathaveyoutried.com/) – 2013-03-01 18:33:29
对不起,请稍后再添加。 – Momo 2013-03-01 18:51:32