Kết quả 1 đến 5 của 5

Chủ đề: Code cho Msgbox

  1. #1
    Ngày tham gia
    Aug 2015
    Bài viết
    0

    Code cho Msgbox

    Mình có tạo một Button command với tên là Clear để nó làm clear content khi mình bấm vào nó. Và đây là code
    "Private Sub CommandButton3_Click()
    Dim rConstants As Range
    Set rConstants = Sheet1.Range("A2:AA500").SpecialCells(xlCellTypeCo nstants)
    rConstants.ClearContents
    End Sub"
    Tuy nhiên có một chút rắc rối là nếu file có số liệu thì nó xóa ok, nhưng nếu đã bấm xóa rồi (nghĩa là số liệu đã bị xóa sạch) mà bấm thêm lần nữa thì nó thông báo "Run-time error '1004' No cells were found". Mình muốn nếu mà số liệu đã xóa sạch rồi thì bấm vào cái button đó nó sẽ hiện lên thông báo là "Done".
    Bạn nào chèn giúp mình msgbox vào dòng lệnh trên giúp mình với, mình ko làm đc. Xin cảm ơn.

  2. #2
    duyhb1990 Guest
    Trích dẫn Gửi bởi bachduongstar
    Mình có tạo một Button command với tên là Clear để nó làm clear content khi mình bấm vào nó. Và đây là code
    "Private Sub CommandButton3_Click()
    Dim rConstants As Range
    Set rConstants = Sheet1.Range("A2:AA500").SpecialCells(xlCellTypeCo nstants)
    rConstants.ClearContents
    End Sub"
    Tuy nhiên có một chút rắc rối là nếu file có số liệu thì nó xóa ok, nhưng nếu đã bấm xóa rồi (nghĩa là số liệu đã bị xóa sạch) mà bấm thêm lần nữa thì nó thông báo "Run-time error '1004' No cells were found". Mình muốn nếu mà số liệu đã xóa sạch rồi thì bấm vào cái button đó nó sẽ hiện lên thông báo là "Done".
    Bạn nào chèn giúp mình msgbox vào dòng lệnh trên giúp mình với, mình ko làm đc. Xin cảm ơn.
    Bạn sửa lại thành vầy xem

    Mã:
    Private Sub CommandButton3_Click()
    On Error Resume Next
    Dim rConstants As Range
    Set rConstants = Sheet1.Range("A2:AA500").SpecialCells(xlCellTypeConstants)
    If rConstants Is Nothing Then
        MsgBox "Done"
    Else
        rConstants.ClearContents
    End If
    End Sub

  3. #3
    aaronmax Guest
    Trích dẫn Gửi bởi huuthang_bd
    Bạn sửa lại thành vầy xem

    <div class="bbcode_container">
    <div class="bbcode_description">Code:
    </div>
    </div>
    Great, tuyệt quá. Cảm ơn bạn, đã làm dc

  4. #4
    benjamin239 Guest
    Tiện thể cho mình hỏi thêm, mình có làm command button để add dữ liệu, và code chạy được. Lệnh code như sau
    "Private Sub Addbutton_Click()Dim emptyRow As Long


    'Make Sheet1 active
    Sheet1.Activate
    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
    'Transfer information
    Cells(emptyRow, 1).Value = txtID.Value
    Cells(emptyRow, 2).Value = txtName.Value
    Cells(emptyRow, 3).Value = CboGender.Value
    Cells(emptyRow, 4).Value = txtAge.Value
    Cells(emptyRow, 5).Value = txtAddress.Value
    Cells(emptyRow, 6).Value = CDate(TextBox6.Value)
    Cells(emptyRow, 7).Value = TextBox7.Value
    Cells(emptyRow, 8).Value = ChbVomit.Value
    Cells(emptyRow, 9).Value = ChbNausea.Value
    Cells(emptyRow, 10).Value = ChbHeadache.Value
    Cells(emptyRow, 11).Value = ChbAbdominal.Value
    Cells(emptyRow, 12).Value = ChbDiarrhea.Value
    Cells(emptyRow, 13).Value = ChbFever.Value
    Cells(emptyRow, 14).Value = ChbDizziness.Value
    Cells(emptyRow, 15).Value = ChbThirst.Value
    Cells(emptyRow, 16).Value = txtOthers.Value
    Cells(emptyRow, 17).Value = txtTimeeat.Value
    Cells(emptyRow, 18).Value = CheckBox1.Value
    Cells(emptyRow, 19).Value = CheckBox2.Value
    Cells(emptyRow, 20).Value = CheckBox3.Value
    Cells(emptyRow, 21).Value = CheckBox4.Value
    Cells(emptyRow, 22).Value = CheckBox5.Value
    Cells(emptyRow, 23).Value = CheckBox6.Value
    Cells(emptyRow, 24).Value = CheckBox7.Value
    Cells(emptyRow, 25).Value = CheckBox8.Value
    Cells(emptyRow, 26).Value = CheckBox9.Value
    Cells(emptyRow, 27).Value = CheckBox10.Value
    End Sub"

    Bây giờ mình muốn làm Tongle button là "Previous" và "Next", mình chưa học qua VBA bao giờ, cũng cố xem trên 4rum để bắt chước nhưng làm mãi vẫn chưa được. Bạn nào giúp được mình thì giúp với. Cảm ơn các bạn và cảm ơn 4rum.

  5. #5
    dungcuthethaohc Guest
    Trích dẫn Gửi bởi bachduongstar
    Tiện thể cho mình hỏi thêm, mình có làm command button để add dữ liệu, và code chạy được. Lệnh code như sau
    "Private Sub Addbutton_Click()Dim emptyRow As Long


    'Make Sheet1 active
    Sheet1.Activate
    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
    'Transfer information
    Cells(emptyRow, 1).Value = txtID.Value
    Cells(emptyRow, 2).Value = txtName.Value
    Cells(emptyRow, 3).Value = CboGender.Value
    Cells(emptyRow, 4).Value = txtAge.Value
    Cells(emptyRow, 5).Value = txtAddress.Value
    Cells(emptyRow, 6).Value = CDate(TextBox6.Value)
    Cells(emptyRow, 7).Value = TextBox7.Value
    Cells(emptyRow, 8).Value = ChbVomit.Value
    Cells(emptyRow, 9).Value = ChbNausea.Value
    Cells(emptyRow, 10).Value = ChbHeadache.Value
    Cells(emptyRow, 11).Value = ChbAbdominal.Value
    Cells(emptyRow, 12).Value = ChbDiarrhea.Value
    Cells(emptyRow, 13).Value = ChbFever.Value
    Cells(emptyRow, 14).Value = ChbDizziness.Value
    Cells(emptyRow, 15).Value = ChbThirst.Value
    Cells(emptyRow, 16).Value = txtOthers.Value
    Cells(emptyRow, 17).Value = txtTimeeat.Value
    Cells(emptyRow, 18).Value = CheckBox1.Value
    Cells(emptyRow, 19).Value = CheckBox2.Value
    Cells(emptyRow, 20).Value = CheckBox3.Value
    Cells(emptyRow, 21).Value = CheckBox4.Value
    Cells(emptyRow, 22).Value = CheckBox5.Value
    Cells(emptyRow, 23).Value = CheckBox6.Value
    Cells(emptyRow, 24).Value = CheckBox7.Value
    Cells(emptyRow, 25).Value = CheckBox8.Value
    Cells(emptyRow, 26).Value = CheckBox9.Value
    Cells(emptyRow, 27).Value = CheckBox10.Value
    End Sub"

    Bây giờ mình muốn làm Tongle button là "Previous" và "Next", mình chưa học qua VBA bao giờ, cũng cố xem trên 4rum để bắt chước nhưng làm mãi vẫn chưa được. Bạn nào giúp được mình thì giúp với. Cảm ơn các bạn và cảm ơn 4rum.
    cho xin file đính kèm bạn ơi !

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •