计算列中的百分比

发布于 2024-09-30 08:13:43 字数 218 浏览 3 评论 0原文

我有一个 Excel 工作表,其中的信息格式类似于测试:

Choice     Chosen        Percentage
A 
B 
C 
D 
TOTAL 
False 
True 
TOTAL 

“选择”列给出了每个选项被选择的次数,以及相应问题的“总行总数”。我需要一种方法来快速找到每个被选择的百分比(选择/总计),但我不知道如何去做。

I have an Excel worksheet with information in a format much like a test:

Choice     Chosen        Percentage
A 
B 
C 
D 
TOTAL 
False 
True 
TOTAL 

The Chosen column gives how many times each choice was selected, and the Total row totals for the corresponding question. I need a way to quickly find the Percentage each was selected (Chosen/Total) but I am not sure how to go about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄暮涼年 2024-10-07 08:13:43

我认为你不需要 VBA。如果我理解这个问题,这只是一个简单的公式。假设这些是标题,并且从单元格 A1 开始,则 b 列(选择为 A)的百分比将类似于 =B2/$F2,并将该列格式化为百分比类型。

请注意,$F 是对 F 的绝对引用,因此当您向下填充时,它始终指向 F 行(总行),但列号会按其应有的方式更改。

I don't think you need VBA for that. It's just a simple formula if I understand the question. Assuming these are headers and it starts at cell A1, then Percentage for column b (choice was A) will be like =B2/$F2 and you format the column as percentage type.

Note the $F is an absolute reference to F so that when you fill down, it always points to row F (total row) but the column number changes as it should.

情绪 2024-10-07 08:13:43

我正在这个窗口中即时编写代码,因此您需要注意错误。另外,您需要输入伪代码的代码,

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 来表示“firstrow”已设置

I am writing code on the fly and in this window itself, so you'd need to watch out for errors. Also, you'll need to put in code for psuedo code

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

I am using frs to signify 'firstrow' has been set

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文