Huỳnh hoài bảo
Huỳnh hoài bảo
Thảo luận 5 thảo luận
Vỗ tay 0 vỗ tay
Lượt xem 240 lượt xem

Trong sub nhap_lieu mình đã khai báo biến dong_cuoi rồi; đến khi mình viết điều

Cho mình hỏi: Trong sub nhap_lieu mình đã khai báo biến dong_cuoi rồi; đến khi mình viết điều kiện cho các ô nhập liệu xong; khi gọi module nhap_lieu ( mọi chuyện OK) nhưng sau đó mình viết thêm phần định dạng bảng thì khi sử dụng lại  biến đó  mà VBA báo là phải khai báo lại - Không biết mình hiểu vậy đúng không?

Thảo luận 5 câu trả lời
Lượt xem 240 lượt xem
Vỗ tay vỗ tay
Huỳnh hoài bảo 09:09 - Sep 09, 2020

Chào bạn bạn có thể đẩy code hoặc hình ảnh lên được không?  trong phần Nhap_lieu của bạn có hàm dong_cuoi không?

Vỗ tay vỗ tay
Huỳnh hoài bảo 17:09 - Sep 10, 2020

Sub nhap_lieu2()

    If Range("B2").Value = "" Then

         MsgBox "Ban phai nhap ho va ten"

    Exit Sub

        ElseIf Range("B3").Value = "" Then

        MsgBox "Ban phai nhap muc luong"

    Exit Sub

        ElseIf Range("B4").Value = "" Then

        MsgBox "Ban phai nhap ngay"

    Exit Sub

        Else

        Call nhap_lieu

     ' Dim dongcuoi As Long

    'Theo minh nghi thi dongcuoi da duoc khai báo o sub nhap_lieu roi

    'dongcuoi = Sheet1.Range("F" & Rows.Count).End(xlUp).Row

   Range("F2:H" & dongcuoi).Select

    Selection.Borders(xlDiagonalDown).LineStyle = xlNone

    Selection.Borders(xlDiagonalUp).LineStyle = xlNone

    With Selection.Borders(xlEdgeLeft)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlEdgeTop)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlEdgeBottom)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlEdgeRight)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlInsideVertical)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlInsideHorizontal)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

  

   End If

Vỗ tay vỗ tay
Huỳnh hoài bảo 17:09 - Sep 10, 2020

chào bạn bạn cần tách như thế này

sub nhaplieuluu

      If Range("B2").Value = "" Then

         MsgBox "Ban phai nhap ho va ten"

    Exit Sub

        ElseIf Range("B3").Value = "" Then

        MsgBox "Ban phai nhap muc luong"

    Exit Sub

        ElseIf Range("B4").Value = "" Then

        MsgBox "Ban phai nhap ngay"

    Exit Sub

        Else

        Call nhap_lieu

   end if

 call dindangnhaplieu

end sub

sub dindangnhaplieu

     Dim dongcuoi As Long

    dongcuoi = Sheet1.Range("F" & Rows.Count).End(xlUp).Row

   Range("F2:H" & dongcuoi).Select

    Selection.Borders(xlDiagonalDown).LineStyle = xlNone

    Selection.Borders(xlDiagonalUp).LineStyle = xlNone

    With Selection.Borders(xlEdgeLeft)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlEdgeTop)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlEdgeBottom)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlEdgeRight)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlInsideVertical)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

    With Selection.Borders(xlInsideHorizontal)

        .LineStyle = xlContinuous

        .ColorIndex = xlAutomatic

        .TintAndShade = 0

        .Weight = xlThin

    End With

end sub


Vỗ tay vỗ tay
Huỳnh hoài bảo 09:09 - Sep 11, 2020

cám ơn thầy - như vậy mình hiểu như vầy không biết có đúng không 

- Biến dòng cuối đã sử dụng ở sub nhaplieuluu  sub này đã thực hiện xong và đã đóng lại

- Kế đó mình định dạng thì phải khai báo lại cho sub dinhdangnhaplieu

Vỗ tay vỗ tay
Huỳnh hoài bảo 09:09 - Sep 11, 2020

Chào bạn đúng rồi ạ

Vỗ tay vỗ tay
Câu hỏi liên quan
© 2020 - Bản quyền của Công Ty Cổ Phần Công Nghệ Giáo Dục Gitiho Việt Nam
Giấy chứng nhận Đăng ký doanh nghiệp số: 0109077145, cấp bởi Sở Kế hoạch và Đầu tư TP. Hà Nội
Giấy phép mạng xã hội số: 588, cấp bởi Bộ Thông tin và Truyền thông