简体   繁体   English

Excel-使用多个工作表中的文本

[英]Excel - working with text across multiple worksheets

I have an excel file that uses multiple worksheets to summarize payments and the payment schedule for multiple properties. 我有一个Excel文件,该文件使用多个工作表来汇总付款和多个属性的付款时间表。

It's set up so that the first sheet is a summary of everything, with subsequent sheets detailing different properties. 设置它的目的是使第一张工作表是所有内容的摘要,随后的工作表详细说明不同的属性。 I have a column (just for descriptions) that I want to bring back the text to the first sheet, and if there are multiple entries on subsequent sheets for it to let me know. 我有一列(仅用于描述),我想将文本带回到第一张纸上,并且如果随后的几张纸上有多个条目,请告诉我。

I know excel doesn't like working with text across multiple worksheets so this code below worked well to bring out a single entry for me. 我知道excel不喜欢在多个工作表中使用文本,因此下面的这段代码很好地为我带来了一个条目。 It will always be in the same cell on subsequent sheets. 它将始终位于后续工作表的同一单元格中。

=IF(COUNTA(Sheet1:Sheet5!D15)=0,"", IF(COUNTA(Sheet1:Sheet5!D15)=1, (Sheet1!D15&Sheet2!D15&Sheet3!D15&Sheet4!D15&Sheet5!D15), "--> Multiple Entries"))

However I've come across a situation where I do need to put two identical entries in subsequent sheets. 但是,我遇到一种情况,我确实需要在后续工作表中放入两个相同的条目。

For an example using | 例如使用| as a sheet break 休息一下

"" | “” | "Paid #1" | “付费1” | "" | “” | ""

"Paid #1" | “付费1” | "Paid #1" | “付费1” | "" | “” | ""

"" | “” | "Paid #2" | “付费2” | "Paid #1" | “付费1” | ""

Case #2 is the odd one where its ok to have multiple identical entries but #3 where they are different needs to be highlighted, as I have it now (--> Multiple Entries) is enough. 第2种情况很奇怪,可以有多个相同的条目,但第3种情况则需要突出显示,因为我现在有了它(->多个条目)就足够了。 Right now both cases would be highlighted. 现在,这两种情况都将突出显示。

I don't know where to start really, I can't find a 3d reference (something along the lines of match) that handles text, any suggestions? 我不知道从哪里真正开始,我找不到处理文本的3D参考(沿匹配线),有什么建议吗?

As always, thanks in advance, I really appreciate all the help. 一如既往,在此先感谢您,我非常感谢所有帮助。

One way would be to write a UDF that returns the required string. 一种方法是编写返回所需字符串的UDF。 Unfortunately UDF parameters don't support 3D ranges, so a work around is required. 不幸的是,UDF参数不支持3D范围,因此需要解决。

Based on your question it apears you want to consider the same cell in all sheets except the summary sheet. 根据您的问题,您想在除汇总表之外的所有表中考虑相同的单元格。 On this basis, this UDF will return a concatenation of the same cell in all sheets except the sheet the formula is placed on. 在此基础上,此UDF将在所有工作表中返回同一单元格的串联,但公式所在的工作表除外。 You can adapt it to return other things as you wish. 您可以根据需要调整它以返回其他内容。

Note that I have kept it simple to demo a method, you would need to handle error cases, like r refering to >1 cell, or a cell on another sheet/workbook. 请注意,我已简化了方法的演示,您将需要处理错误情况,例如r引用> 1单元格,或另一张工作表/工作簿上的单元格。

Function MergeSheets(r As Range) As Variant
    Dim a As String, s As String
    Dim sh As Worksheet
    Application.Volatile

    a = r.Address
    For Each sh In r.Worksheet.Parent.Worksheets
        If sh.Name <> r.Worksheet.Name Then
            s = s & sh.Range(a).Value
        End If
    Next
    MergeSheets = s
 End Function

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM