英文:
Excel autofill dates but not totally sequentially
问题
我试图创建一个简单的Excel电子表格,每天追踪一些事情3次(早上、中午和晚上)。表格应该如下所示:
日期 | 时段 | 事情1 | 事情2 | 事情3 |
---|---|---|---|---|
26/06/2023 | 早上 | x | y | z |
26/06/2023 | 中午 | x | y | z |
26/06/2023 | 晚上 | x | y | z |
27/06/2023 | 早上 | x | y | z |
27/06/2023 | 中午 | x | y | z |
27/06/2023 | 晚上 | x | y | z |
28/06/2023 | 早上 | x | y | z |
28/06/2023 | 中午 | x | y | z |
28/06/2023 | 晚上 | x | y | z |
以为这会很简单,但无法让Excel以这种方式自动填充日期(3次相同,然后递增)。
也许有一个简单的公式我没有考虑到?
英文:
I'm trying to create a simple excel spreadsheet which tracks some things 3 times per day (morning, noon, and night). The table should look like this:
Date | Time of Day | Thing 1 | Thing 2 | Thing 3 |
---|---|---|---|---|
26/06/2023 | Morning | x | y | z |
26/06/2023 | Noon | x | y | z |
26/06/2023 | Night | x | y | z |
27/06/2023 | Morning | x | y | z |
27/06/2023 | Noon | x | y | z |
27/06/2023 | Night | x | y | z |
28/06/2023 | Morning | x | y | z |
28/06/2023 | Noon | x | y | z |
28/06/2023 | Night | x | y | z |
Thought this would be simple but can't get Excel to autofill in that way with dates (3 x same, and then increment).
Maybe there's a simple formula I'm not thinking of?
答案1
得分: 3
创建数据表格
- 日期列需要手动格式化。
- 可能(很可能)用单元格引用替换输入。
对于“事件”和“事物”,每个值使用一个单元格。
=LET(FirstDate,DATEVALUE("26-6-2023"),dDays,5,
Events,VSTACK("早上","中午","晚上"),
Things,HSTACK("x","y","z"),
ec,TOCOL(Events),tr,TOROW(Things),
eRows,ROWS(ec),totRows,eRows*dDays,tCols,COLUMNS(tr),
d,FirstDate+INT(SEQUENCE(totRows,,0)/eRows),
e,INDEX(ec,MOD(SEQUENCE(totRows,,0),eRows)+1),
t,INDEX(tr,SEQUENCE(totRows,,1,0),SEQUENCE(,tCols)),
HSTACK(d,e,t))
- 如果要保留硬编码的值,这可能是更好的方法:
=LET(FirstDate,DATEVALUE("26-6-2023"),dDays,5,
Events,"早上,中午,晚上",Things,"x,y,z",
ec,TOCOL(TEXTSPLIT(Events,",")),tr,TOROW(TEXTSPLIT(Things,",")),
eRows,ROWS(ec),totRows,eRows*dDays,tCols,COLUMNS(tr),
d,FirstDate+INT(SEQUENCE(totRows,,0)/eRows),
e,INDEX(ec,MOD(SEQUENCE(totRows,,0),eRows)+1),
t,INDEX(tr,SEQUENCE(totRows,,1,0),SEQUENCE(,tCols)),
HSTACK(d,e,t))
英文:
Create Table Data
- The date column needs to be formatted manually.
- Possibly (probably) replace the inputs with cell references.
ForEvents
andThings
use one cell per value.
=LET(FirstDate,DATEVALUE("26-6-2023"),dDays,5,
Events,VSTACK("Morning","Noon","Night"),
Things,HSTACK("x","y","z"),
ec,TOCOL(Events),tr,TOROW(Things),
eRows,ROWS(ec),totRows,eRows*dDays,tCols,COLUMNS(tr),
d,FirstDate+INT(SEQUENCE(totRows,,0)/eRows),
e,INDEX(ec,MOD(SEQUENCE(totRows,,0),eRows)+1),
t,INDEX(tr,SEQUENCE(totRows,,1,0),SEQUENCE(,tCols)),
HSTACK(d,e,t))
- If you want to keep the values hardcoded, this could be a better approach:
=LET(FirstDate,DATEVALUE("26-6-2023"),dDays,5,
Events,"Morning,Noon,Night",Things,"x,y,z",
ec,TOCOL(TEXTSPLIT(Events,",")),tr,TOROW(TEXTSPLIT(Things,",")),
eRows,ROWS(ec),totRows,eRows*dDays,tCols,COLUMNS(tr),
d,FirstDate+INT(SEQUENCE(totRows,,0)/eRows),
e,INDEX(ec,MOD(SEQUENCE(totRows,,0),eRows)+1),
t,INDEX(tr,SEQUENCE(totRows,,1,0),SEQUENCE(,tCols)),
HSTACK(d,e,t))
答案2
得分: 2
=MAKEARRAY(B2*3,5,
LAMBDA(r,c,
CHOOSE(IF(c>3,3,c),
INT(B1+(r-1)/3),
CHOOSE(MOD(r-1,3)+1,"morning","noon","night"),
CHOOSE(c-2,"x","y","z"))))
其中:B1
是开始日期,B2
是要列出的不同日期数。
英文:
=MAKEARRAY(B2*3,5,
LAMBDA(r,c,
CHOOSE(IF(c>3,3,c),
INT(B1+(r-1)/3),
CHOOSE(MOD(r-1,3)+1,"morning","noon","night"),
CHOOSE(c-2,"x","y","z"))))
Where: B1
is the start date
and B2
is the number of different days to list.
答案3
得分: 1
=IF(COUNTIFS($B$1:B1,"="&B1)=3,B1+1,B1)
Then you can do this for Morning Noon and night:
=IF(COUNTIFS($B$1:B4,"="&B4)=1,"Morning",IF(COUNTIFS($B$1:B4,"="&B4)=2,"Noon",IF(COUNTIFS($B$1:B4,"="&B4)=3,"Night","Error")))
英文:
So like this:
IF(COUNTIFS($B$1:B1,"="&B1)=3,B1+1,B1)
Then you can do this for Morning Noon and night:
=IF(COUNTIFS($B$1:B4,"="&B4)=1,"Morning",IF(COUNTIFS($B$1:B4,"="&B4)=2,"Noon",IF(COUNTIFS($B$1:B4,"="&B4)=3,"Night","Error")))
But a simple vlookup() is easier:
答案4
得分: 1
以下是您要的中文翻译:
你也可以尝试这个:
• 单元格 B5
中使用的公式
=LET(
_nOfDays,E3,
_timeOfDay,{"早上","中午","晚上"},
_todCols,COLUMNS(_timeOfDay),
_rowsNeeded,_nOfDays*_todCols,
_firstDate,DATE(D3,B3,C3),
_dateIncrement,_firstDate+INT(SEQUENCE(_rowsNeeded,,0,1/_todCols)),
_timeOfDayfill,INDEX(_timeOfDay,MOD(SEQUENCE(_rowsNeeded,,0),_todCols)+1),
_things,{"x","y","z"},
_header,HSTACK("日期","时段","事物"&SEQUENCE(,COLUMNS(_things))),
IFERROR(VSTACK(_header,
HSTACK(_dateIncrement,_timeOfDayfill,IFNA(_things,SEQUENCE(ROWS(_timeOfDayfill))))),
"请在相应单元格中输入月份、日期、年份和天数"))
更简单的方法,不使用 LAMBDA()
=LET(
a,H1,
b,I1,
c,SEQUENCE(b*3,,0),
d,INT(a+c/3),
e,INDEX({"早上","中午","晚上"},MOD(c,3)+1),
f,IFNA({"x","y","z"},SEQUENCE(b*3)),
HSTACK(d,e,f))
或者,替代 INDEX( ) 使用 SWITCH( )
=LET(
a,H1,
b,I1,
c,SEQUENCE(b*3,,0),
d,INT(a+c/3),
e,SWITCH(MOD(c,3)+1,1,"早上",2,"中午","晚上"),
f,IFNA({"x","y","z"},SEQUENCE(b*3)),
HSTACK(d,e,f))
英文:
You could try this as well:
• Formula used in cell B5
=LET(
_nOfDays,E3,
_timeOfDay,{"Morning","Noon","Night"},
_todCols,COLUMNS(_timeOfDay),
_rowsNeeded,_nOfDays*_todCols,
_firstDate,DATE(D3,B3,C3),
_dateIncrement,_firstDate+INT(SEQUENCE(_rowsNeeded,,0,1/_todCols)),
_timeOfDayfill,INDEX(_timeOfDay,MOD(SEQUENCE(_rowsNeeded,,0),_todCols)+1),
_things,{"x","y","z"},
_header,HSTACK("Date","Time Of Day","Things"&SEQUENCE(,COLUMNS(_things))),
IFERROR(VSTACK(_header,
HSTACK(_dateIncrement,_timeOfDayfill,IFNA(_things,SEQUENCE(ROWS(_timeOfDayfill))))),
"Please enter the Month,Day,Year and #ofDays in respective cells"))
Bit simpler approach without <kbd>LAMBDA()</kbd>
=LET(
a,H1,
b,I1,
c,SEQUENCE(b*3,,0),
d,INT(a+c/3),
e,INDEX({"Morning","Noon","Night"},MOD(c,3)+1),
f,IFNA({"x","y","z"},SEQUENCE(b*3)),
HSTACK(d,e,f))
OR, inplace of <kbd>INDEX( )</kbd> use <kbd>SWITCH( )</kbd>
=LET(
a,H1,
b,I1,
c,SEQUENCE(b*3,,0),
d,INT(a+c/3),
e,SWITCH(MOD(c,3)+1,1,"Morning",2,"Noon","Night"),
f,IFNA({"x","y","z"},SEQUENCE(b*3)),
HSTACK(d,e,f))
答案5
得分: 1
在单元格 A1 输入起始日期
在单元格 B1 ="早上"
在单元格 B2 =IF(B1="早上","中午",IF(B1="中午","晚上",IF(B1="晚上","早上","早上")))
在单元格 A2 =IF(B2="早上",A1+1,A1)
拖动以自动填充这些公式。
英文:
Formula Method:
In Cell A1 Enter starting Date
In Cell B1 ="Morning"
In Cell B2 =IF(B1="Morning","Noon",IF(B1="Noon","Night",IF(B1="Night","Morning","Morning")))
In Cell A2 =IF(B2="Morning",A1+1,A1)
Drag to autofill the formulas down.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论