【发布时间】:2014-05-08 00:15:08
【问题描述】:
所以我有一个格式如下的矩阵:
| | joe | michelle | tom |
|:-----: |:---: |:--------: |:---: |
| red | 1 | 0 | 1 |
| blue | 0 | 1 | 0 |
| green | 0 | 0 | 0 |
我正在尝试在 excel 中编写 VBA 以基于此表创建两列。如果矩阵内的单元格等于“1”,那么我想将列名和行名写入一个列表。例如,因为“red”行在“joe”和“tom”列中有一个“1”,而“blue”行在“michelle”下有一个“1”,我的新表将是这样的:
| joe | red |
| tom | red |
| michelle | blue |
这是我到目前为止编写的 VBA,但它不起作用,我遇到了障碍。
sub subname()
dim i as integer
for i = 1 to 3
if cells(2,i).value=1 then
cell(5,i).value = cells(1,i).value
end if
next i
end sub
【问题讨论】:
-
1 列可以包含多于 1 个数字 1 的实例吗?即名称可以有不止一种颜色吗?