Mai Minh Đông
Mai Minh Đông
Thảo luận 6 thảo luận
Vỗ tay 0 vỗ tay
Lượt xem 238 lượt xem

huhuem đang làm bài tập chương 7 và em muốn thêm phần kẻ khung cho Sheet("Data")

huhu.
em đang làm bài tập chương 7 và em muốn thêm phần kẻ khung cho Sheet("Data") nhưng sao không được thầy.
câu lệnh này (Sheets("Data").Range("A" & DongCuoi & ":E" & DongCuoi).Select) nếu bỏ Sheets("Data") thì nó kẻ khung cho Sheet("themmoi")
còn để nguyên thì báo lỗi
thầy giúp em ...rối quá

Sub Ke_Khung3()
'
' Ke_Khung3 Macro
'
Dim DongCuoi As Long
DongCuoi = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Data").Range("A" & DongCuoi & ":E" & DongCuoi).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Thảo luận 6 câu trả lời
Lượt xem 238 lượt xem
Vỗ tay vỗ tay
Mai Minh Đông 11:06 - Jun 11, 2020
Chào bạn bạn có thể đẩy file lên được không? ở đây bước bạn phải chọn chỉ là vùng cuối cùng kẻ ô thôi đúng không?
'Sheets("Data").Range("A" & DongCuoi & ":E" & DongCuoi).Select đoạn này bị sai này.
bạn xem code mẫu
Option Explicit

Sub kedong()
Dim dc As Long, vungchon As Variant
dc = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
Sheet1.Range("A" & dc, "D" & dc).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Vỗ tay vỗ tay
Mai Minh Đông 09:06 - Jun 12, 2020
vẫn lỗi thầy ạ
thầy xử lý giúp với ạ
các câu lệnh ở dưới thầy xem và sửa giúp
bài tập chương 7
sub kedong em để Sheeet2 hoặc sheets("Data") đều lỗi ạ


Sub Luu_Du_Lieu()
Dim DongCuoi As Long
DongCuoi = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
'Sheet Data phai luon duoc mo khoa
'Sheets("Data").Unprotect Password:="1"
'Xac dinh ket qua luu
Sheets("Data").Range("A" & DongCuoi + 1).Value = Sheets("ThemMoi").Range("A3").Value 'Ten hang
Sheets("Data").Range("B" & DongCuoi + 1).Value = Sheets("ThemMoi").Range("E3").Value 'DVT
Sheets("Data").Range("C" & DongCuoi + 1).Value = Sheets("ThemMoi").Range("A6").Value 'So luong
Sheets("Data").Range("D" & DongCuoi + 1).Value = Sheets("ThemMoi").Range("C6").Value 'don gia
Sheets("Data").Range("E" & DongCuoi + 1).Value = Sheets("ThemMoi").Range("E6").Value 'thanh tien
'Khoa sheet lai
'Sheets("Data").Protect Password:="1"
End Sub

Sub Xoa_Du_Lieu()
Sheets("ThemMoi").Range("A3:C3, A6").ClearContents
End Sub

Sub Luu_Du_Lieu_KetQua()
Call Luu_Du_Lieu
Call Xoa_Du_Lieu
Call kedong
MsgBox "Luu du lieu thanh cong"
End Sub



Sub kedong()
Dim dc As Long, vungchon As Variant
dc = Sheet2.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
Sheet2.Range("A" & dc, "E" & dc).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub




Vỗ tay vỗ tay
Mai Minh Đông 09:06 - Jun 12, 2020
Ở đây bạn dùng record macro cho thao tác kẻ khung nên sẽ có vấn đề là Code dài và sử dụng đối tượng làm việc Selection.
Không nên làm việc theo cách này mà bạn làm việc trực tiếp luôn (không thông qua bước .Select nữa):
Sub Ke_Khung3()
Dim DongCuoi As Long
DongCuoi = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
'Câu lệnh kẻ khung rút gọn lại chỉ như thế này
With Sheets("Data").Range("A" & DongCuoi & ":E" & DongCuoi)
.Borders.LineStyle = xlContinuous
End With

End Sub
Vỗ tay vỗ tay
Mai Minh Đông 09:06 - Jun 12, 2020
ok.đã được rồi thầy
cảm ơn thầy ạ
Vỗ tay vỗ tay
Mai Minh Đông 14:10 - Oct 26, 2020

thầy ơi cho e hỏi ạ:
- biến dòng cuối khi mình đã khai báo ở module này rồi thì ở module khác có dùng được biến dòng cuối này không ah?
- làm thế nào để khi nhập và nhấn lưu thêm dữ liệu vào bảng thì macro kẻ khung sẽ tự động chạy mà không cần chạy lại macro? (không tính cách gán macro vào 1 shape ạ)

Vỗ tay vỗ tay
Mai Minh Đông 15:10 - Oct 26, 2020

Chào bạn với vba bạn tạo ra function dòng cuối rồi tìm lại dòng cuối tại module bạn đó bạn nhé.

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