我在 Excel 工作表中有数据。具体来说,我在列D
和 E
(和其他一些)中有数据。我要填写的栏目F
,并 G
用一个公式,使用从列中的数据D
和 E
。规则是:
Fn
Dn
Dn
F(n+1)
F(n+2)
F(n+3)
D(n+1)
D(n+2)
D(n+3)
TRIM()
G
应该来自E
遵循相同的规则。第二个子弹隐藏了一个微妙的陷阱。考虑这些数据:
排 | D | 乙 | F | G |
---|---|---|---|---|
59 | 沮丧 | 废话59 | 沮丧 | 废话59 |
60 | 高于平均水平 | 废话60 | 沮丧 | 废话60 |
61 | 沮丧 | blah61 | 沮丧 | blah61 |
62 | 平均数 | blah62 | 沮丧 | blah62 |
63 | 平均数 | blah63 | 平均数 | blah63 |
64 | 高于平均水平 | blah64 | 高于平均水平 | blah64 |
F59
是“抑郁症”,因为它与D59
. 但是,既然D59
是“抑郁症”, F60
, F61
并且 F62
也被设置为“抑郁症”,并且D60
, D61
和 D62
被忽略。具体来说,我们忽略了同样D61
是“抑郁症”的事实,因此我们不会将F63
and 设置F64
为“抑郁症”,而是让它们等于D63
and D64
。
有些已张贴(错误地)设置的答案F63
,并 F64
为“抑郁症”。
编辑:
如果 D 列中是“恶性通货膨胀”、“恶性通货膨胀”或“萧条”、“恶性通货膨胀”,您将如何解决?
What I would like it to look like:
"Depression","Hyperinflation" Worksheet:
What I would like it to look like:
So in column D, if the cell is "Hyperinflation" or "Depression", and within the next three cells there is another "Hyperinflation" or "Depression", I would not want to repeat them in column F. So the "Hyperinflation" or "Inflation" within the next three cells in column D would be ignored.
Dropbox Link: https://www.dropbox.com/scl/fi/wxfzk0r320wm57r7jge5b/PART-B.xlsx?dl=0&rlkey=z407ft00oi9e0i4m9qlvmmirh
I believe that it is impossible to do what the question asks for with a closed-form, single-cell formula. Consider the following hypothetical data, with the corresponding desired results (as I understand the requirements):
Row | D | F | ||
---|---|---|---|---|
72 | ant | ant | ||
73 | bat | bat | ||
74 | cat | cat | ||
75 | dog | dog | ||
76 | Depression | ← | Depression | ← |
77 | illustration | Depression | ← | |
78 | jackpot | Depression | ← | |
79 | Depression | ⇐ | Depression | ← |
80 | kangaroo | kangaroo | ||
81 | leopard | leopard | ||
82 | Depression | ← | Depression | ← |
83 | melody | Depression | ← | |
84 | nighthawk | Depression | ← | |
85 | Depression | ⇐ | Depression | ← |
86 | orange | orange | ||
87 | purple | purple |
There's no local difference between Rows 83 & 84 and Rows 86 & 87. I believe it's impossible for a formula in Column F
(or G
) to distinguish between those cases without looking at the entire D
column.
Luckily, it seems to be fairly easy with helper columns. Pick two columns that you aren't using. They can be H
and I
, Y
and Z
, AF
and AG
, or whatever you want. I'll assume that you choose H
and I
.
Assuming that your data start in Row 15 (as your question shows) and that cells H14
and I14
are empty (which should be the case, since I've assumed that you aren't using the helper columns), enter
=IF(AND(H14>0,H14<4), H14+1, --OR(TRIM(SUBSTITUTE(D15, CHAR(160), " "))="Depression",TRIM(SUBSTITUTE(D15, CHAR(160), " "))="Hyperinflation"))
into cell H15
, and enter
=IF(H15>1, "Depression", TRIM(SUBSTITUTE(D15, CHAR(160), " ")))
into cell F15
. Copy F
into G
and H
into I
, and drag/fill down.
The value in the helper column is "normally" 0. When H(n-1)
is 0, Hn
is set to --OR(D15="Depression",D15="Hyperinflation")
(the final part of the IF
expression). We use TRIM()
because the data in your file have trailing spaces, which cause the string comparison to fail. We use SUBSTITUTE(cell, CHAR(160), " ")
because the data in your file have trailing non-breaking spaces, which TRIM()
doesn't handle, so we have to convert those to regular spaces before calling TRIM()
. This OR
expression is TRUE
if Dn
is equal to one of the two trigger words, and FALSE
otherwise. The --
turns these into 1 and 0. A value of 1 indicates that this is the first row of a repeat block; a 0 indicates that it is another normal row.
如果为正但小于 4,则表示第n-1行 是重复块的一部分(但不是最后一行),因此第n行 必须是重复块的一部分(但不是第一行)。因此我们添加 1(表达式的中间部分),以表示第 n行是重复块的第 2、第 3 或第 4 行。如果 是 4,我们回到基于 的 设置。H(n-1)
IF
H(n-1)
Hn
Dn
column 的公式F
表示如果第 n行是重复块的第 2、3 或 4 行,则设置为“凹陷”;否则,它被设置为等于 。Fn
Dn
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句