如何用vba在excel中实现,单击单元格,单元格里的数自增一? EXCEL如何实现每打印一张单元格里的数字自动加1
excel\u4e2d\u600e\u4e48\u5b9e\u73b0\u6309\u4e00\u4e0b\uff0c\u8ba9\u5355\u5143\u683c\u7684\u6570\u503c\u81ea\u52a8\u52a011\u3001\u5148\u8f93\u5165\u9009\u9879\u548c\u9898\u76ee\u3002
2\u3001\u6309\u4f4falt+F11\uff0c\u51fa\u73b0\u5982\u4e0b\u7a97\u53e3\u3002
3\u3001\u6253\u5f00\u4ee3\u7801\u7a97\u53e3\uff0c\u628a\u5982\u4e0b\u4ee3\u7801\u590d\u5236\u8fdb\u53bb\uff0cPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)Target = Target + 1End Sub\u3002
4\u3001\u4fdd\u5b58\u540e\u5173\u95ed\u7a97\u53e3\u3002
5\u3001\u6700\u540e\u5c31\u662f\u8fd9\u6837\u70b9\u4e00\u4e0b\uff0c\u6570\u5b57\u5c31\u4f1a \u52a0\u4e00\uff0c\u5f04\u597d\u4e4b\u540e\u518d\u6309alt+F11\uff0c\u628a\u4ee3\u7801\u5220\u9664\uff0c\u4fdd\u5b58\u5373\u53ef\u3002
\u540c\u65f6\u6309Alt\u548cF11\uff0c\u8fdb\u5165VBA\u754c\u9762\uff0c\u5728\u5de6\u4e0a\u7a97\u53e3\u627e\u5230Thisworkbook\uff0c\u53cc\u51fb\u5b83\uff0c\u5728\u53f3\u8fb9\u7a97\u53e3\u7c98\u8d34\u5982\u4e0b\u4ee3\u7801\uff1aPrivate Sub Workbook_BeforePrint(Cancel As Boolean) Sheets("Sheet1").Range("A2") = Sheets("Sheet1").Range("A2") + 1 End Sub \u6362\u6210\u5b9e\u9645\u7684\u5de5\u4f5c\u8868\u540d\u5b57\u548c\u6570\u5b57\u6240\u5728\u5355\u5143\u683c\u3002\u56de\u5230Excel\u4e2d\uff0c\u529f\u80fd\u5b9e\u73b0\u3002 \u7528\u624b\u673a\u8f93\u5165\u7684\uff0c\u95ee\u95ee\u4e0d\u7ed9\u6362\u884c\uff0c\u8bf7\u53c2\u89c1\u6211\u7684 http://wenwen.soso.com/z/q167756319.htm
\u5e0c\u671b\u91c7\u7eb3
答:照下图打开代码窗口
然后把下面代码复制进去即可:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.HasFormula Then Exit Sub
If VBA.IsNumeric(Target.Value) Then
Target = Target + 1
End If
End Sub
同一个单元格点就无效了
定制doubleclick事件
这招都想到了,。我还一直想是不是要调用哪个API呢!
绛旓細1銆侀鍏堬紝鍦‥xcel涓寜蹇嵎閿淎lt + F11鈥锛屽涓嬪浘鎵绀恒2銆佸叾娆★紝鍦╒BA缂栬緫鍣ㄤ腑渚濇鍗曞嚮鈥滄彃鍏モ-->鈥滄ā鍧椻濓紝濡備笅鍥炬墍绀恒3銆佺劧鍚庯紝鍦ㄢ滄ā鍧椻濅腑杈撳叆濡備笅浠g爜锛歄ption Explicit Sub addwork()Sheets.Add after:=Sheets(Sheets.Count)End Sub 4銆佹帴鐫锛屽湪VBA缂栬緫鍣ㄧ殑宸︿晶杈撳叆妯″潡鐨勫悕绉帮紝濡備笅...
绛旓細浠g爜濡備笅:Sub 鑾峰彇VBA鐗堟湰()MsgBox Application.VBE.Version End Sub 褰撴寜F5閿紝灏辨姤锛氳繍琛屾椂閿欒1004銆傜粡鑰佸笀鎸囩偣锛屽崟鍑绘枃浠垛曗曢夐」鈥曗曚俊浠讳腑蹇冣曗曟墦寮鈥滀俊浠讳腑蹇冣濆璇濇锛屽畯璁剧疆鈥曗曞嬀閫夆滀俊浠诲VBA宸ョ▼瀵硅薄妯″瀷鐨勮闂濄傚啀娆¤繍琛岋紝灏变笉浼氬嚭鐜拌繍琛屾椂閿欒1004鎻愮ず銆傚悗鏉ュ湪寰蒋瀹樻柟涔熺湅鍒颁簡姝ゆ秷鎭...
绛旓細1.鐐瑰嚮榧犳爣鍙抽敭锛岄夋嫨鈥滄柊寤衡濋夐」锛岀劧鍚庣偣鍑烩渕ircosoft office Excel 2007鈥濋夐」鏂板缓涓涓狤xcel鏂囦欢銆2.鍒朵綔闇瑕侀殣钘忕殑鐩稿叧琛ㄦ牸銆3.閫夋嫨鐣岄潰涓婃柟鐨勨滃紑鍙戝伐鍏封濋夐」锛岀劧鍚庣偣鍑烩滃畯鈥濋夐」銆4.鍐欐槑VBA浠g爜鍚嶇О锛岀劧鍚庣偣鍑烩滃垱寤衡濇寜閽5.鍐欏叆鎸囧畾鐨刅AB浠g爜銆備綔鑰呰繖閲岄渶瑕侀殣钘忚〃鏍间腑鐨2-4鍜9-11琛屻6.鐐瑰嚮...
绛旓細鍦‥xcel涓紝鍒╃敤VBA鍙互杞绘澗瀹炵幇璺ㄥ伐浣滅翱鐨勬暟鎹皟鐢ㄣ棣栧厛锛屼綘闇瑕佸湪宸ヤ綔绨跨殑瀹忓綍鍒跺姛鑳戒腑寮濮嬫搷浣溿傜偣鍑诲乏涓嬭鐨勫綍鍒跺畯鎸夐挳锛屼负鍗冲皢鎵ц鐨勬搷浣滃垱寤轰竴涓畯銆傚湪瀹忓悕澶勶紝杈撳叆涓涓槗鐞嗚В鐨勫悕绉帮紝渚嬪"DataTransfer"锛屽苟閫夋嫨瀛樺偍鍦"涓汉瀹忓伐浣滅翱"涓紝鐒跺悗鐐瑰嚮"纭畾"銆傚綍鍒跺畬鎴愬悗锛岄氳繃鐐瑰嚮鍋滄褰曞埗瀹忔寜閽殏鍋...
绛旓細If Target.Column = 2 Then 鈥欏彧鍦ㄧ浜屽垪瀹炵幇璇ュ姛鑳 If Target.Value = 1 Then Target.Value = 涓杞﹂棿 Else If Target.Value = 2 Then Target.Value = 浜岃溅闂 Else If Target.Value = 3 Then Target.Value = 閿鍞儴 End If End If End If End If End Sub 杩斿洖鍒Excel绐楀彛锛岃繖鏃惰緭鍏...
绛旓細鍦‥xcel涓浣跨敤鍑芥暟鍏紡锛屾湁涓ょ浣跨敤鏂规硶锛屼竴鏄洿鎺ラ氳繃榧犳爣鎴栨墜宸ヨ緭鍏ョ殑鏂规硶浣跨敤锛岀О涓虹洿鎺ヤ娇鐢紱浜屾槸閫氳繃VBA闂存帴璋冪敤銆傜О涓洪棿鎺ユ硶銆傞氳繃VBA璋冪敤Excel涓殑鍑芥暟锛屽叿鏈夌浉褰撶殑鐏垫椿鎬э紝褰撴垜浠湪澶勭悊鏈煡鍖哄煙鍗充笉纭畾鏈夊灏戣鍜屽灏戝垪鐨勬椂鍊欙紝濡傛灉浣跨敤VBA璋冪敤鍑芥暟锛岄偅涔堬紝灏嗘槸涓绉嶇◢鏈夋櫤鑳芥х殑鏁版嵁澶勭悊鏂规硶銆備笅闈...
绛旓細Excel涓娇鐢╲ba鏉ュ畾鏃惰繍琛岀▼搴忕殑鎿嶄綔姝ラ濡備笅锛氶鍏堟垜浠墦寮涓涓伐浣滄牱琛ㄤ綔涓轰緥瀛愩備娇鐢╝lt+f11缁勫悎蹇嵎閿繘鍏be缂栬緫鍣紝鎻掑叆涓涓柊鐨勬ā鍧楋紝骞跺湪妯″潡涓緭鍏ヤ互涓嬩唬鐮侊細Sub myProcedure()MsgBox ("绁濅綘鐢熸棩蹇箰")End Sub 杩欎釜杩囩▼寰堢畝鍗曪紝灏辨槸鏄剧ず涓涓浣犵敓鏃ュ揩涔愮殑瀵硅瘽妗嗭紝浣嗘槸姝e父鐨勯渶瑕佹縺娲昏繍琛岋紝浣嗘槸...
绛旓細鎵撳紑Excel骞舵寜涓婣LT + F11鎵撳紑VBA缂栬緫鍣ㄣ傚湪VBA缂栬緫鍣ㄤ腑锛岄夋嫨鈥滄彃鍏モ> 鈥滄ā鍧椻濅互鍒涘缓涓涓柊妯″潡銆傚湪妯″潡涓紪鍐欐偍鐨刅BA浠g爜浠ュ垱寤篍xcel鏂囦欢銆備互涓嬫槸涓涓畝鍗曠殑绀轰緥锛屽皢鍦ㄦ柊宸ヤ綔绨夸腑鍒涘缓涓涓伐浣滆〃骞跺~鍏呮暟鎹細vba 澶嶅埗Sub CreateExcelFile()Dim ExcelApp As Object Dim ExcelWorkbook As Object Dim...
绛旓細1銆佸彲浠ュ厛鍒╃敤瀹忓綍鍒舵潵鑷姩鐢熸垚浠g爜锛岀劧鍚庡啀杩涜淇敼銆傛搷浣滄柟娉曞涓嬶細绗竴姝ワ紝鎵撳紑涓涓excel搴旂敤锛屾柊寤轰竴涓櫧绌鸿〃鏍硷紝骞跺綍鍏ユ暟鎹2銆佺浜屾锛岀偣鍑籩xcel搴旂敤绋嬪簭绐楀彛鐘舵佹爮涓乏渚х殑鈥滃畯褰曞埗鈥濇寜閽3銆佺涓夋锛岀劧鍚庡湪琛1涓紝閫変腑宸︿笂瑙掔涓涓湁鏁版嵁鐨勫崟鍏冩牸銆4銆佺鍥涙锛屾帴鐫鎸変笅CTRL+SHIFT閿紝鍐...
绛旓細Q锛氭垜鎯浣跨敤VBA浠g爜鍦ㄥ崟鍏冩牸涓緭鍏ユ暟缁勫叕寮忥紝濡備綍瀹炵幇锛烝锛歊ange瀵硅薄鎻愪緵浜嗕竴涓狥ormulaArray灞炴э紝鍙互鐢ㄦ潵璁剧疆鎴栬呰繑鍥炲崟鍏冩牸鍖哄煙涓殑鏁扮粍鍏紡锛屼篃灏辨槸璇达紝鍦ㄥ伐浣滆〃鍗曞厓鏍间腑杈撳叆瀹屽悗闇瑕佹寜Ctrl+Shift+Enter缁勫悎閿墠鑳芥渶缁堝畬鎴愮殑鍏紡銆傚涓嬫墍绀猴紝瑕佹眰宸ヤ綔琛⊿heet2涓墍鍒楀嚭鐨勬按鏋滄荤殑閿鍞噾棰濓紝鍗冲垎鍒娇鐢ㄥ悇绉...