我试图让我的代码正确但在某些时候失败:我有一个 Excel 表,它根据顶部单元格中写入的值将一个单元格与下面的一个单元格合并,但是当从合并的单元格中删除一个值时我'd希望单元格取消合并。我尝试使用 sub 来保持我的代码有点干净(不知道正确的规则,但我尝试):
Public Sub LetItMerge(Target As Object)
If Target.Value = Empty Then
Call unMergeCell(Target)
Else
If (Target.Value = VV Then Call MergeCell(Target)
End If
End Sub
Sub unMergeCell(m As Object)
m.Resize(1, 1).UnMerge
m.Borders(xlInsideHorizontal).LineStyle = XlLineStyle.xlContinuous
End Sub
Sub MergeCell(n As Object)
n.Resize(2).Merge 'merge cells
n.VerticalAlignment = xlCenter 'center text
n.HorizontalAlignment = xlCenter 'center text
End Sub