我有一个 Excel 工作表,其中的信息格式很像测试:
Choice Chosen Percentage
A
B
C
D
TOTAL
False
True
TOTAL
Chosen 列给出了每个选项被选中的次数,以及对应问题的 Total 行总计。我需要一种方法来快速找到每个被选中的百分比(选择/总计),但我不知道如何去做。
我有一个 Excel 工作表,其中的信息格式很像测试:
Choice Chosen Percentage
A
B
C
D
TOTAL
False
True
TOTAL
Chosen 列给出了每个选项被选中的次数,以及对应问题的 Total 行总计。我需要一种方法来快速找到每个被选中的百分比(选择/总计),但我不知道如何去做。
我认为您不需要VBA。如果我理解这个问题,这只是一个简单的公式。假设这些是标题并且它从单元格 A1 开始,那么列 b(选择 A)的百分比将类似于 =B2/$F2 并且您将该列格式化为百分比类型。
请注意,$F 是对 F 的绝对引用,因此当您填写时,它始终指向 F 行(总行),但列号会发生变化。
我正在动态编写代码并在此窗口本身中编写代码,因此您需要注意错误。此外,您需要为伪代码输入代码
dim currRow as integer
dim frs as boolean
firstRow = 1
frs = false
range("A1").select
<loop over column A until you reach a blank value>
If selection.value == "Choice" then
' move to next row, nothing to see here
else if not selection.value == "Total" then
if frs = false then
firstRow = selection.row
frs = true
endif
else if selection.value = "Total" then
frs = false
dim i as integer
for i = firstRow to selection.row -1
range("C" + cstr(i)).formula = "=B"+ cstr(1)+"/B" + cstr (selection.row) ' or something to that effect
next
end if
Selection.cells(2,1).select ' selects the next cell vertically
end loop
我正在使用 frs 表示已设置“第一行”