使用VBA来alignment特定的单元格
我是VBA新手,想知道是否有人可以帮助下面的代码:
Sub Macro1() With Selection If Cell = "Detail" Then .HorizontalAlignment = xlRight End If End With End Sub
基本上,我想使用VBA来将任何单元格与“细节”一词alignment。 任何人都可以请帮忙?
考虑:
Sub ToTheRight() Dim r As Range For Each r In Selection If r.Value = "Detail" Then r.HorizontalAlignment = xlRight End If Next r End Sub
编辑#1:
此版本将对find的行进行颜色编码:
Sub ToTheRight() Dim r As Range For Each r In Selection If r.Value = "Detail" Then r.HorizontalAlignment = xlRight Intersect(r.EntireRow, ActiveSheet.UsedRange).Interior.ColorIndex = 27 End If Next r End Sub