![](/img/trans.png)
[英]Excel VBA Macro to make highlighted cells be the same as the next non-highlighted cell above it
[英]Apply Excel VBA macro to all highlighted cells
在此先感谢您,我是excel VBA的新手。 这个问题可能非常简单,但是我没有在广泛的搜索中找到答案。 我最初记录了此宏,并使用在网上找到的内容对其进行了调整。 如果您一次套用至一个储存格(或如果您拖曳多列,将在最左上角储存格的行上使用),这个巨集就会运作。 有没有一种方法可以进一步调整它,使我的宏将更改应用于所有选定单元格的行,以便用户可以批量更改行?
Range("A" & ActiveCell.Row & ":I" & ActiveCell.Row).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
Range("A" & ActiveCell.Row).Select
ActiveCell.FormulaR1C1 = "5"
Range("B" & ActiveCell.Row & ":I" & ActiveCell.Row).Select
With Selection.Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = True
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
Range("B" & ActiveCell.Row).Select
结束子
也许这就是你所追求的?
'Instead of this:
'Range("A" & ActiveCell.Row & ":I" & ActiveCell.Row).Select
'Do this:
With Application.Intersect(Selection.EntireRow, Range("A:I")).Interior
'The range at hand is now all the cells in the rows of the selection,
' but limited to columns A:I.
'Notice we haven't actually modified the selection
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
'Range("A" & ActiveCell.Row).FormulaR1C1 = "5"
Application.Intersect(Selection.EntireRow, Range("A:A")).FormulaR1C1 = "5"
'Range("B" & ActiveCell.Row & ":I" & ActiveCell.Row).Select
With Application.Intersect(Selection.EntireRow, Range("B:I")).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = True
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
Range("B" & ActiveCell.Row).Select
注意:不必先.SELECT
一个范围,然后再执行something
。 通常,您可以将something
应用于范围。 您开始时通常会使用宏记录器代码,只是知道有一种更干净的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.