合并一个单元格,取决于它的价值 [英] Merge a cell in excel, depending on it's value
问题描述
如果单元格具有一定的值(vv)
,我想自动将单元格与下面的单元格合并。
a解决方案我发现是每次更改数据时检查数组中的每个单元格,但认为有可能检查单元格
的值已更改
?
I want to merge a cell automatically with the one underneath if the cell has a certain value ("vv")
.
a solution i found is to check every cell in an array every time a change is made, but thought there would be a possibility to check the value of a cell
after it changed
?
所以如果我输入一个空白单元格vv
(不带引号),我选择一个不同的单元格'像这样的单元格(与其中的vv)合并在一个正确的单元格下。
在我的解决方案与数组它需要一秒钟,每次你更改一个单元格,这是不整洁,如果你做了很多变化。
任何帮助?
So if I enter in a blank cell "vv"
(without quotes) and I select a different cell I'd like that cell (with vv in it) to merge with the one right under it.
in my solution with the array it takes a second every time you change a cell, which is not neat if you make a lot of changes.
Any help?
推荐答案
在您的工作表中尝试此代码:
Try this code in your worksheet:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "vv" Then Target.Resize(2).Merge
End Sub
如果您想防止以下单元格中的任何内容,则此代码将询问您是否将合并单元格以防发现任何内容:
In case you want to prevent any content in the cell below, this code will ask you if the cells shall be merged in case any content is found:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "vv" Then
If Target.Offset(1).Value "" Then
If MsgBox("Do you want to overwrite the cell below (containing '" & _
Target.Offset(1) & "?", vbYesNo) = vbYes Then
Target.Resize(2).Merge
End If
Else
Target.Resize(2).Merge
End If
End If
End Sub
注意:代码需要放在目标表中,而不是新的模块,如这是一个事件过程:
Note: The code needs to go in the target sheet, not a new module, as it is an Event procedure:
这篇关于合并一个单元格,取决于它的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!