1、首先打开Microsoft Office Excel 2007,上例文件保存文件名《Excel怎样以一操百(批量自动标颜色) .xlsm》(演示文件,下面代码复制到能运行宏的工作簿都可以)如图。
2、然后按下快捷键ALT+F11打开VBE(宏)编辑界面,然后点菜单栏【插入】下拉中列表中点【模块(M)】如图。
3、然后插入了一个模块1,在代码框中复制如下代码:Sub 选批量标颜色() 补朱锚卦39;2020-9-17 23:08:19 Dim myr1 As Range, myr2 As Range, myr1s As Range, myr2s As Range Set myr1s = Selection Set myr2s = Application.InputBox(Prompt:="选择标色数字的单元格区域", Type:=8) For Each myr2 In myr2s For Each myr1 In myr1s If myr1.Value = myr2.Value Then myr1.Font.Color = myr2.Font.Color End If Next myr1 Next myr2End Sub
4、以上操作动态过程如下:
5、回到工作表窗口,首先选原数据表,然后运行【选批量标颜色】宏(菜单栏中点【视图】中下列表中【宏】列表【查看宏(V)】打开宏对方框,选该宏名,执行),提示“选择标色数字的单元格区域”,选好上面原选数据相同标相同颜色,运行过程如下图。