![](/img/trans.png)
[英]VBA Excel - Auto run macro to insert new blank row after cell above has value entered
[英]Excel Macro to change cell alignment, borders and wrap text if a value has been entered into another cell in the same row
我正在尝试创建一个excel宏,如果将值输入到该特定行内的一个单元格中,则该宏将更新单元格对齐方式,在每行中换行文本和边框。 例如,如果在单元格A1中输入了一个值,则我希望宏更新单元格A1:O1的换行文本,单元格对齐方式和边框。 不幸的是,将条件格式应用于电子表格中的每一行都非常麻烦,并且只能处理单元格边界的更新,因此,我认为最好是可以更新所有3个单元格格式元素并动态搜索整个工作表的宏。
谢谢你的协助!
我不知道您想如何触发此宏,也不知道要应用哪种确切格式,但是我将做以下事情:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
With Range(Target, Target.Offset(0,14)
.HorizontalAlignment = xlCenter
.WrapText = True
.Font.Bold = True
.Borders(xlEdgeBottom).LineStyle = xlContinuous
End with
end if
End Sub
编辑:添加按钮和分配宏窗口将出现。 选择新建,然后将代码放在此处。
For Each Target in Range(Cells(1,1), Cells(65536, 1).End(xlUp))
If Target <> "" Then
With Range(Target, Target.Offset(0,14)
.HorizontalAlignment = xlCenter
.WrapText = True
.Font.Bold = True
.Borders(xlEdgeBottom).LineStyle = xlContinuous
End With
End If
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.