如何保留每个单元格中合并单元格的值?
我创建了一个包含合并单元格的工作表,但合并单元格的值仅存储在第一个单元格中。无论如何,为了在每个单元格中保持相同的值,我使用的公式需要它。谢谢!
I created a sheet with merged cells, but the value of the merged cells is only stored in the first cell. Is there anyway, to keep the same value in each of the cells, I need that for a formula I use. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在 Excel 2003 中,此宏执行以下操作:
通过按 Alt-F11、Ctrl-R、菜单
Insert/Module
创建宏UnmergeAndFill
),单击Make
或创建
(?不知道英文按钮文本)按 Alt-F8 调用宏,选择它,
运行
。或者将其映射到一个键In Excel 2003 this macro does the job:
Create the macro by
Insert/Module
, paste the code;UnmergeAndFill
, e.g.), clickMake
orCreate
(? don't know the English button text)Invoke the Macro by pressing Alt-F8, select it,
Run
. Alternatively map it to a key您可以使用自定义 VBA 函数来直接给出合并单元格的值,无论您选择哪一个。在这种情况下,没有必要重复这些值。
代码:
:
其中 A1 是合并单元格的一部分。
You could use a custom VBA function that gives directly the value of the merged cell, no matter which one you select. In that case it is not necessary to duplicate the values.
Code:
Code:
Where A1 is a part of a merged cell.
我知道这是一个相当老的问题,但这是我在寻找答案时遇到的第一个地方,而接受的答案根本没有帮助。然而,我确实在 MrExcel 上发现了一个很好的答案,我认为值得将其放在这个线程上,以便其他人在谷歌上搜索答案:
http://www.mrexcel.com/forum/general-excel-discussion-other-questions/487941-data-multiple-cells-within-merged-cell-possible.html
保存查找链接,答案非常简单;如果您使用 Excel 格式刷而不是合并单元格来合并单元格,它会保留合并单元格“下方”的数据/公式。您只需要在其他地方以正确的格式创建临时合并的单元格块,以用作格式刷的模板。您可以稍后删除它们。不过,需要注意的一件事是,像这样的“隐藏”数据对于粗心的人来说可能是一个陷阱,因为编辑可见单元格不会更改不可见的单元格。
I know this is a rather old question, but this is the first place I landed when looking for an answer, and the accepted answer did not help at all. I DID discover an excellent answer, however, on MrExcel which I thought was worth putting on this thread for the benefit of anyone else googling for an answer:
http://www.mrexcel.com/forum/general-excel-discussion-other-questions/487941-data-multiple-cells-within-merged-cell-possible.html
To save looking up the link, the answer is remarkably simple; if you merge cells using Excel Format Painter, rather than Merge Cells, it preserves the data/formulae 'underlying' the merged cells. You just need to create a temporary merged block of cells in the right format somewhere else, to use as a template for the Format Painter. You can delete them afterwards. One thing to watch out for, though, is having 'hidden' data like this can be a trap for the unwary, since editing the visible cell does not change the invisible ones.
您可以创建一个新列(或行)并在第一个单元格中应用此公式并将其向下拖动:
我想在 A 列中您已合并单元格(例如 A1:A3 和 A5:A8 已合并)。
在 A 列之前插入一列
在 A1 中键入:
<前><代码>=B1
将以下公式复制到 A2 中:
<预置><代码>=IF(B2="",A1,B2)
向下拖动在 A2 中输入的公式
在公式中使用新创建的列,使用后即可可以隐藏它。
you can make a new column (or row) and apply this formula in first cell and drag it down:
I suppose in column A you have merged cells (for example A1:A3 & A5:A8 are merged).
Insert a column before column A
In A1 type:
Copy the formula below in A2 :
Drag down the formula u typed in A2
In your formulas use the newly created column and after use you can hide it.
你不能将实际值存储在其他地方吗?而不是合并单元格?是的,使用公式显示合并单元格上的值。
can you not store the actual values somewhere else? instead of the merged cell? and yes , use a formula to display the value on the merged cell.
假设“A”列已合并单元格 - 将其放入 B1 中并复制它以填充该列的其余部分:
它检查左侧的单元格是否有值,如果有,则返回其值,如果没有,则采用该值从上单元。
请注意,它不适用于空单元格。首先用一些独特的东西填充“A”列中的空单元格,例如“(空)”,并在填充“B”列后将“A”和“B”中的空单元格替换回空。
Assume column "A" has merged cells - put this in B1 and copy it to fill the rest of the column:
It checks if the cell to the left has a value if it has it returns its value, if not, it takes the value from the upper cell.
Note that it doesn't work for the empty cells. First fill empty cells in column "A" with something unique, like "(empty)" and replace it back with emptiness both in "A" and "B" after filling column "B".
我改进了 sehe 的宏,可以根据您的选择执行尽可能多的合并单元格。
代码:
I improved on sehe's macro to do as many merged cells as you select.
Code:
假设 A13 到 A52 已合并。
a = Cells(13,1)
将返回一个值,但是a = Cells(14,1)
不会“空”修复:
a = Cells(X,1).MergeArea(1, 1) '如果 x=13 到 52 将在 A13 中返回值。
不知道我是如何让它发挥作用的,但它确实有效。
Say A13 through A52 are merged.
a = Cells(13,1)
will return a value buta = Cells(14,1)
will not "Empty"Fix:
a = Cells(X,1).MergeArea(1, 1) 'if x=13 through 52 will return value in A13.
don't know how i got this to work but it works.