资源描述:
《excel常用宏集合》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、65:删除包含固定文本单元的行或列Sub删除包含固定文本单元的行或列()DoCells.Find(what:="哈哈").ActivateSelection.EntireRow.Delete'删除行'Selection.EntireColumn.Delete'删除列LoopUntilCells.Find(what:="哈哈")IsNothingEndSub72:在指定颜色区域选择单元时添加/取消"√"(工作表代码)PrivateSubWorksheet_SelectionChange(ByValTargetA
2、sRange)DimmyrgAsRangeForEachmyrgInTargetIfmyrg.Interior.ColorIndex=37Thenmyrg=IIf(myrg<>"√","√","")NextEndSub73:在指定区域选择单元时添加/取消"√"(工作表代码)PrivateSubWorksheet_SelectionChange(ByValTargetAsRange)DimRngAsRangeIfTarget.Count<=15ThenIfNotApplication.Intersect(Tar
3、get,Range("D6:D20"))IsNothingThenForEachRngInSelectionWithRngIf.Value=""Then.Value="√"Else.Value=""EndIfEndWithNextEndIfEndIfEndSub74:双击指定单元,循环录入文本(工作表代码)PrivateSubWorksheet_BeforeDoubleClick(ByValTAsRange,CancelAsBoolean)IfT.Address<>"$A$1"ThenExitSubCance
4、l=TrueT=IIf(T="好","中",IIf(T="中","差","好"))EndSub75:双击指定单元,循环录入文本(工作表代码)DimnumsAsBytePrivateSubWorksheet_BeforeDoubleClick(ByValTargetAsRange,CancelAsBoolean)IfTarget.Address="$A$1"Thennums=numsMod3+1Target=Mid("上中下",nums,1)Target.Offset(1,0).SelectEndIfEndSu
5、b76:单元区域引用(工作表代码)PrivateSubWorksheet_Activate()Sheet1.Range("A1:B3").Value=Sheet2.Range("A1:B3").ValueEndSub77:在指定区域选择单元时数值加1(工作表代码)PrivateSubWorksheet_SelectionChange(ByValTargetAsRange)IfNotApplication.Intersect([a1:e10],Target)IsNothingThenTarget=Val(Tar
6、get)+1EndIfEndSub259个常用宏-excelhome(3)2009-08-1514:12:5878:混合文本的编号Sub混合文本的编号()Worksheets(1).Range("B2").Value="北京"&(--(Mid(Worksheets(1).Range("B2"),3,100))+1)EndSub79:指定区域单元双击数据累加(工作表代码)PrivateSubWorksheet_BeforeDoubleClick(ByValTargetAsRange,CancelAsBoolea
7、n)IfNotApplication.Intersect([A1:Y100],Target)IsNothingThenoldvalue=Val(Target.Value)inputvalue=InputBox("请输入数量,按ENTER键确认!","数值累加器")Target.Value=oldvalue+inputvalueEndIfEndSub80:选择单元区域触发事件(工作表代码)PrivateSubWorksheet_SelectionChange(ByValTargetAsRange)IfTarge
8、t.Address="$A$1:$B$2"ThenMsgBox"你选择了$A$1:$B$2单元"EndIfEndSub81:当修改指定单元内容时自动执行宏(工作表代码)PrivateSubWorksheet_Change(ByValTargetAsRange)IfNotApplication.Intersect(Target,[B3:B4])IsNothingThen重排窗口EndIfEndSub8