简体   繁体   English

Excel 连接不同类型单元格的单元格值

[英]Excel concatenate cell values from cells of different types

I have an Excel spreadsheet where I'm unable to concatenate a line to group the cells together.我有一个 Excel 电子表格,我无法连接一行以将单元格组合在一起。 In my spreadsheet I input dates and times to auto-add hours (a schedule with daily start/stop times).在我的电子表格中,我输入日期和时间以自动添加小时数(包含每日开始/停止时间的时间表)。 I'm trying to find a way to string these together to insert the lines into a Word doc.我试图找到一种方法将它们串在一起以将这些行插入到 Word 文档中。

Excel: (* indicates formula/calculation) Excel:(*表示公式/计算)

| | DATE |日期 | START |开始| STOP |停止 | Total*|总计*| Day* |天* | ddd* | DD* |

| | 2/27/23 | 2/27/23 | 8:00 AM |上午 8:00 | 7:00 PM |下午 7:00 | 11 | 11 | Mon |星期一 | 2/27 | 2/27 |

I've tried using =text() and =value() but nothing seems to get me the information I need in a string.我试过使用 =text() 和 =value() 但似乎没有任何东西可以让我在字符串中获得我需要的信息。 I do not want to do a copy/paste - the idea is to input the data once, and have another sheet read that in to a chart that can be inserted in to Word.我不想做复制/粘贴——我的想法是输入一次数据,然后让另一张纸将其读入可以插入到 Word 中的图表中。 What am I missing..?我错过了什么..?

=CONCATENATE(Rates!I9," ",Rates!H9," from ",Rates!C9," to ",Rates!D9) 

I was expecting: Mon 2/27 from 8:00 AM to 7:00 PM我期待:2 月 27 日星期一上午 8:00 到晚上 7:00

I'm getting: Mon 44984 from 0.333333333333333 to 0.895833333333333我得到:周一 44984 从 0.333333333333333 到 0.895833333333333

This is one way to do it.这是一种方法。 Let's generate in A2 a timestamp via NOW() function, and in B2 two hours after NOW() + 2/24 .让我们通过NOW() function 在A2中生成一个时间戳,并在NOW() + 2/24两小时后在B2中生成一个时间戳。 Then in C2 you can build the following output as follow:然后在C2中,您可以按如下方式构建以下 output:

=CONCAT(TEXT(A2, "ddd mm/dd"), " from ", 
 TEXT(A2-TRUNC(A2), "hh:mm AM/PM"), " to ",  
 TEXT(B2-TRUNC(B2), "hh:mm AM/PM"))

Note : Dates in excel are represented as a Whole number and the time is the decimal part of that number.注意:excel 中的日期表示为整数,时间是该数字的小数部分。 The first hour is represented as 1/24 .第一个小时表示为1/24

Or you can create a user LAMBDA function to get the decimal part ( GETDEC ) to simplify it:或者您可以创建一个用户LAMBDA function 来获取小数部分 ( GETDEC ) 以简化它:

=LET(GETDEC, LAMBDA(x, x-TRUNC(x)), CONCAT(TEXT(A2, "ddd mm/dd"), " from ",
 TEXT(GETDEC(A2), "hh:mm AM/PM"), " to ",  TEXT(GETDEC(B2), "hh:mm AM/PM")))

Here is the output:这是 output:

示例输出文件

or just putting it all together in a user LAMBDA function ( GET_TIME_INFO ) that can be used inside a LET function:或者只是将它们放在一个用户LAMBDA function ( GET_TIME_INFO ) 中,可以在LET function 中使用:

=LET(GET_TIME_INFO, LAMBDA(a,b, LET(GETDEC, LAMBDA(x, x-TRUNC(x)),
 CONCAT(TEXT(a, "ddd mm/dd"), " from ",
  TEXT(GETDEC(a), "hh:mm AM/PM"), " to ",  TEXT(GETDEC(b), "hh:mm AM/PM"))
 )), GET_TIME_INFO(A2,B2)
)

or you can define it in Name Manager and just use it, like any other regular Excel function: GET_TIME_INFO(A2,B2) .或者您可以在名称管理器中定义它并使用它,就像任何其他常规 Excel function: GET_TIME_INFO(A2,B2)一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel-从一组单元格中检索单元格值 - Excel - retrieving cell values from a group of cells 在Excel 2010中,如何在包含多个值单元格的单元格范围内删除重复项并连接值? - In Excel 2010, how could I remove duplicates and concatenate values within a cell range that includes multiple values cells? 如何从单个单元格获取特定值并将其放入Excel VBA中的不同单元格 - How to get particular values from single cell and put into different cells in Excel VBA 连接单元格中的不同列值 - Concatenate different columns values in a cell 以粗体和斜体excel vba连接不同的单元格 - concatenate different cells in bold and italic excel vba 连接单元格,但之前检查值-Excel VBA - Concatenate cells but check values before - Excel VBA Microsoft Excel替换来自其他单元格的单元格中的数据 - Microsoft Excel replace data from cells from a different cell Excel:如果一行中的一个单元格等于它下面的单元格,则连接单元格的内容 - Excel: If a cell in a row is equal to the cell underneath it, concatenate the contents of the cells 即使公式选择不同的单元格,连接也会重复第一行单元格值 - Concatenate repeats first row cell values even though formula selects different cells 如何从不同的单元格中检索2个值并在不同的单元格中格式化它们? - How to retrieve 2 values from different cells and format them in a different cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM