Nhờ viết code VBA cho vắng mặt hàng ngày (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

kimthoa89

Thành viên thường trực
Tham gia
3/11/17
Bài viết
219
Được thích
17
Giới tính
Nữ
Nhờ anh chị giúp vba cho bảng vắng mặt hàng ngày theo điều kiện ah
em cảm ơn anh chị !
 

File đính kèm

Bạn xài macro sự kiện này:
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            MsgBox "Xong Rôi!", , "GPE.COM Xin Chào!"
        End With
    End If
End If
End Sub
 
Bạn xài macro sự kiện này:
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            MsgBox "Xong Rôi!", , "GPE.COM Xin Chào!"
        End With
    End If
End If
End Sub
Em cảm ơn ah, em đã làm được rùi ah
Nhưng cho em hỏi chút ah. Nếu em nhập sang sheet tong hợp bây h em muốn xóa dữ lieu đó thì phải làm sao ạ
Với lại em nhập stt khác thì stt ở trên vẫn chưa đc xóa bỏ ah
 

File đính kèm

PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
 If Dg Then         'X  => '
    Rows(Dg & ":" & Dg).Delete
 End If                 '<=     X         '
 Exit Sub
GPE:    MsgBox "Xong Rôi!", , "GPE.COM Xin Chào!"
End Sub
 
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dg As Long             'X  '
If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
End If
If Dg Then         'X  => '
    Rows(Dg & ":" & Dg).Delete
End If                 '<=     X         '
Exit Sub
GPE:    MsgBox "Xong Rôi!", , "GPE.COM Xin Chào!"
End Sub


Em muốn xóa chữ xong rùi ah, mong anh chị giúp
 
Lần chỉnh sửa cuối:
mình bỏ rùi nhưng chạy lại báo lỗi, vì mình chưa hiểu nhiều về mac
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dg As Long 'X '
If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
Dim Rws As Long
On Error GoTo GPE
If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
Dg = Target.Row
With Sheet2
Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
.Cells(Rws, "C").Value = [I1].Value
Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
.Cells(Rws, "A").Value = Cells(Target.Row, "B").Value 'STT '
End With
End If
End If
If Dg Then 'X => '
Rows(Dg & ":" & Dg).Delete
End If '<= X '
Exit Sub

End Sub
 
mình bỏ rùi nhưng chạy lại báo lỗi, vì mình chưa hiểu nhiều về mac
Bạn thử lại
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
 If Dg Then         'X  => '
    Rows(Dg & ":" & Dg).Delete
 End If                 '<=     X         '
GPE:    Exit Sub
End Sub
 

File đính kèm

Bạn thử lại
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
 If Dg Then         'X  => '
    Rows(Dg & ":" & Dg).Delete
 End If                 '<=     X         '
GPE:    Exit Sub
End Sub

Bị mất thông báo xong rồi, nhưng lại bị cắt bạn đó từ file data ah
 
Bị mất thông báo xong rồi, nhưng lại bị cắt bạn đó từ file data ah
Thoa thử lại

Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
GPE:    Exit Sub
End Sub
 

File đính kèm

Thoa thử lại

Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
GPE:    Exit Sub
End Sub
Anh ơi, khi nhập lý do vào thì nó không nhảy ra khoảng trắng ah, mà lý do vẫn xuất hiện ở đó ah
 
Anh ơi, khi nhập lý do vào thì nó không nhảy ra khoảng trắng ah, mà lý do vẫn xuất hiện ở đó ah
Là nhập xong xóa lý do đúng không?
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
Range("I4:I1000").ClearContents
GPE:    Exit Sub

End Sub
 

File đính kèm

Là nhập xong xóa lý do đúng không?
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Dg As Long             'X  '
 If Not Intersect(Target, [I4].Resize([B3].CurrentRegion.Rows.Count)) Is Nothing Then
    Dim Rws As Long
    On Error GoTo GPE
    If Cells(Target.Row, "C").Value <> "" And Target.Value <> "" Then
        Dg = Target.Row
        With Sheet2
            Rws = .Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
            .Cells(Rws, "C").Value = [I1].Value
            Cells(Target.Row, "C").Resize(, 7).Copy Destination:=.Cells(Rws, "D")
            .Cells(Rws, "A").Value = Cells(Target.Row, "B").Value           'STT        '
        End With
    End If
 End If
Range("I4:I1000").ClearContents
GPE:    Exit Sub

End Sub
ok đúng rùi ah, em cảm ơn anh nhìu nhé
 
Web KT

Bài viết mới nhất

Back
Top Bottom