将Excel VBAmacros应用于所有突出显示的单元格

提前谢谢,我对excel VBA很新颖。 这个问题可能是非常基本的,但是我没有在广泛的search中find答案。 我最初logging这个macros,并用我在网上find的东西调整它。 如果您一次应用于一个单元格(或者如果拖动多行,将工作在最左上angular的单元格的行上),则此macros将起作用。 有没有办法我可以进一步调整它让我的macros应用更改到所有选定单元格的行,以便用户可以批量更改行?

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 。 你开始的macros代码是典型的,只要知道有一个更清晰的方法。