Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1950|回复: 5

[已解决]VBA程序加一行確定

[复制链接]
发表于 2016-7-7 21:15 | 显示全部楼层 |阅读模式
請問在此程序執行之前加一行,"你是否確定" 按 Y =執行,按 N =返回,即不執行程式,請看附圖 圖.jpg
最佳答案
2016-7-8 08:11
bear-ricky 发表于 2016-7-7 23:07
Sub save()
With Sheets("紀錄")
        R = .Cells(65536, 1).End(xlUp).Row + 1
  1. Sub save()
  2.     If MsgBox("你是否確定", vbYesNo, "提示") = vbYes Then
  3.     With Sheets("紀錄")
  4.         R = .Cells(65536, 1).End(xlUp).Row + 1
  5.         .Cells(R, 1) = [k7]
  6.         .Cells(R, 2) = [k6]
  7.         .Cells(R, 3) = [b3]
  8.         .Cells(R, 4) = [C10]
  9.         .Cells(R, 5) = [H10]
  10.         .Cells(R, 6) = [I10]
  11.         .Cells(R, 7) = [K23]
  12.         Range("A3").Select
  13.     Selection.ClearContents
  14.     Range("C8:D8").Select
  15.     Selection.ClearContents
  16.     Range("A10:A22").Select
  17.     Selection.ClearContents
  18.     Range("H10:H22").Select
  19.     Selection.ClearContents
  20.     Range("L6").Value2 = Range("L6").Value2 + 1
  21.     Range("A3").Select
  22.     End With
  23.     End If
  24. End Sub
复制代码
发表于 2016-7-7 22:28 | 显示全部楼层
If MsgBox("您是否确定?", vbYesNo, "提示") = vbYes Then
       这里加入你之前的with部分代码
End If

以后提问直接上附件,或者贴代码,请不要截图!
回复

使用道具 举报

发表于 2016-7-7 22:28 | 显示全部楼层
Sub test()
  Dim res
  res = MsgBox("你是否确定", vbOKCancel)
  If res = 1 Then
    MsgBox "在这里输入你的代码" '在这里输入你要执行的代码
  Else
    Exit Sub
  End If
End Sub
回复

使用道具 举报

 楼主| 发表于 2016-7-7 23:07 | 显示全部楼层
hyfire2008 发表于 2016-7-7 22:28
Sub test()
  Dim res
  res = MsgBox("你是否确定", vbOKCancel)

Sub save()
With Sheets("紀錄")
        R = .Cells(65536, 1).End(xlUp).Row + 1
        .Cells(R, 1) = [k7]
        .Cells(R, 2) = [k6]
        .Cells(R, 3) = [b3]
        .Cells(R, 4) = [C10]
        .Cells(R, 5) = [H10]
        .Cells(R, 6) = [I10]
        .Cells(R, 7) = [K23]
        Range("A3").Select
    Selection.ClearContents
    Range("C8:D8").Select
    Selection.ClearContents
    Range("A10:A22").Select
    Selection.ClearContents
    Range("H10:H22").Select
    Selection.ClearContents
    Range("L6").Value2 = Range("L6").Value2 + 1
    Range("A3").Select
    End With
   
End Sub

請問怎樣加,加在何處
回复

使用道具 举报

发表于 2016-7-8 08:11 | 显示全部楼层    本楼为最佳答案   
bear-ricky 发表于 2016-7-7 23:07
Sub save()
With Sheets("紀錄")
        R = .Cells(65536, 1).End(xlUp).Row + 1
  1. Sub save()
  2.     If MsgBox("你是否確定", vbYesNo, "提示") = vbYes Then
  3.     With Sheets("紀錄")
  4.         R = .Cells(65536, 1).End(xlUp).Row + 1
  5.         .Cells(R, 1) = [k7]
  6.         .Cells(R, 2) = [k6]
  7.         .Cells(R, 3) = [b3]
  8.         .Cells(R, 4) = [C10]
  9.         .Cells(R, 5) = [H10]
  10.         .Cells(R, 6) = [I10]
  11.         .Cells(R, 7) = [K23]
  12.         Range("A3").Select
  13.     Selection.ClearContents
  14.     Range("C8:D8").Select
  15.     Selection.ClearContents
  16.     Range("A10:A22").Select
  17.     Selection.ClearContents
  18.     Range("H10:H22").Select
  19.     Selection.ClearContents
  20.     Range("L6").Value2 = Range("L6").Value2 + 1
  21.     Range("A3").Select
  22.     End With
  23.     End If
  24. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2016-7-8 21:10 | 显示全部楼层
老司机带带我 发表于 2016-7-8 08:11

已解決,多謝,是否按一下圖像下的最佳答案便可以
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-27 08:38 , Processed in 0.476140 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表