Các anh chị và các thầy cho em hỏi tự động căn chỉnh vùng đã gộp để vừa nội dung có trong vùng đó

Liên hệ QC

Bùi Thúy Thúy

Thành viên thường trực
Tham gia
2/7/18
Bài viết
289
Được thích
38
Khi in biên bản, em lấy dữ liệu từ Sheet "List" để in
Em có sử dụng code để in các sheet "NTNB"; sheet"YCTN"; sheet"NT A_B"
Vùng dữ liệu được lấy từ nội dung Sheet "List" sang các các sheet "NTNB"; sheet"YCTN"; sheet"NT A_B" được em bôi màu vàng
Cho em được hỏi làm thế nào để khi in tự động ( em có dùng code để in có trong file đính kèm) dữ liệu được link sang các sheet "NTNB"; sheet"YCTN"; sheet"NT A_B" thì vùng màu vàng đó tự động căn chỉnh để phù hợp với nội dung đã có
- em cũng đã dùng code tự căn chỉnh nội dung trong vùng được gộp (vùng bôi vàng) nhưng khi dữ liệu được lấy sang phải tác đông Enter vào nó thì nó mới căn chỉnh được chứ khi in tự động thì dữ liệu vẫn không được căn chỉnh tự động với nội dung được link sang (code có trong file đính kèm)
Em xin cảm ơn ạ!
1.png12.png345.png
 

File đính kèm

  • ok.xlsm
    58 KB · Đọc: 23
Lần chỉnh sửa cuối:
anh cho em hỏi dùng có giới hạn gì không ạ!
Đây là bản đầy đủ chứ ạ! em thấy giao diện có chút giống phần mềm QLCL của GXD.
Không có giới hạn gì cả. Đây là phiên bản thử ngiệm trước đây mình viết. Giờ mình phát triển bản khác nhiều tính năng hơn nữa nên chia sẻ cho mọi người dùng. Giao diện giống vì mình lấy luôn file biểu mẫu của GXD để viết code.
 
Upvote 0
Không có giới hạn gì cả. Đây là phiên bản thử ngiệm trước đây mình viết. Giờ mình phát triển bản khác nhiều tính năng hơn nữa nên chia sẻ cho mọi người dùng. Giao diện giống vì mình lấy luôn file biểu mẫu của GXD để viết code.
Vâng, em muốn tải bản Full thì vào đâu ạ!
Em cám ơn anh
 
Upvote 0
Lâu lâu mải mê kiếm ăn bên ngoài không vào diễn đàn.
Tặng anh em file này mình làm từ năm 2015. Chắc chắn sẽ giải quyết được mọi vấn đề mọi người đang bàn luận.
1 file làm toàn bộ HS QLCL. + Nhật ký từng ngày. + In ấn hàng loạt
Mọi người tải về tự nghiên cứu và tùy chỉnh.
pass vba để chỉnh sửa: omdjsc
Thanks anh+
Nhưng sao Sheet VL em không bấm chuột phải được để nhập dữ liệu?
 

File đính kèm

  • grt.png
    grt.png
    53.6 KB · Đọc: 17
Lần chỉnh sửa cuối:
Upvote 0
Chào anh, anh ơi cho em hỏi chút:
em có xem đoạn code anh giúp em để dòng phù hợp với nội dung trong ô được gộp.
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(FitRows).EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
"17" ở đây nghĩa là gi vậy anh?
 
Upvote 0
Địa chỉ các dòng mà bạn muốn co dãn chiều cao.
Anh ơi? Giả sử em muốn thêm dòng "5" hoặc nhiều dòng bất kỳ để giãn dòng thì thêm vào phần nào trong code ạ?
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(FitRows).EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Range("a1:a10, a16").entirerow.autofit

Áp dụng cho dòng 1 tới dòng 10 và dòng 16
Lắp giúp em vào luôn code đi anh cho hoàn thiện hì
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(FitRows).EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Lắp giúp em vào luôn code đi anh cho hoàn thiện hì
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(FitRows).EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
Thay dòng đó vào dòng rows(.... của code cũ đó. Minh ko ngồi máy tinh....
 
Upvote 0
Dòng "Row" là dòng số 4
Vậy còn dòng đầu? có "17"
Khi nào ngồi máy giúp mình nhé!
Mình làm thế này thấy được nè
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(17).EntireRow.AutoFit
    Rows(18).EntireRow.AutoFit
    Rows(19).EntireRow.AutoFit
    Rows(20).EntireRow.AutoFit
    Rows(21).EntireRow.AutoFit
    Rows(22).EntireRow.AutoFit
    Rows(23).EntireRow.AutoFit
    Rows(24).EntireRow.AutoFit
    Rows(25).EntireRow.AutoFit
    Rows(26).EntireRow.AutoFit
    Rows(28).EntireRow.AutoFit
    Rows(29).EntireRow.AutoFit
    Rows(30).EntireRow.AutoFit
    Rows(31).EntireRow.AutoFit
    Rows(32).EntireRow.AutoFit
    Rows(33).EntireRow.AutoFit
    Rows(34).EntireRow.AutoFit
    Rows(35).EntireRow.AutoFit
    Rows(36).EntireRow.AutoFit
    Rows(37).EntireRow.AutoFit
    Rows(38).EntireRow.AutoFit
    Rows(39).EntireRow.AutoFit
    Rows(40).EntireRow.AutoFit
    Rows(41).EntireRow.AutoFit
    Rows(42).EntireRow.AutoFit
    Rows(43).EntireRow.AutoFit
    Rows(44).EntireRow.AutoFit
    Rows(45).EntireRow.AutoFit
    Rows(46).EntireRow.AutoFit
    Rows(47).EntireRow.AutoFit
    Rows(48).EntireRow.AutoFit
    Rows(49).EntireRow.AutoFit
    Rows(50).EntireRow.AutoFit
    Rows(51).EntireRow.AutoFit
    Rows(52).EntireRow.AutoFit
    Rows(53).EntireRow.AutoFit
    Rows(54).EntireRow.AutoFit
    Range("A17:A54").EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Mình làm thế này thấy được nè
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(17).EntireRow.AutoFit
    Rows(18).EntireRow.AutoFit
    Rows(19).EntireRow.AutoFit
    Rows(20).EntireRow.AutoFit
    Rows(21).EntireRow.AutoFit
    Rows(22).EntireRow.AutoFit
    Rows(23).EntireRow.AutoFit
    Rows(24).EntireRow.AutoFit
    Rows(25).EntireRow.AutoFit
    Rows(26).EntireRow.AutoFit
    Rows(28).EntireRow.AutoFit
    Rows(29).EntireRow.AutoFit
    Rows(30).EntireRow.AutoFit
    Rows(31).EntireRow.AutoFit
    Rows(32).EntireRow.AutoFit
    Rows(33).EntireRow.AutoFit
    Rows(34).EntireRow.AutoFit
    Rows(35).EntireRow.AutoFit
    Rows(36).EntireRow.AutoFit
    Rows(37).EntireRow.AutoFit
    Rows(38).EntireRow.AutoFit
    Rows(39).EntireRow.AutoFit
    Rows(40).EntireRow.AutoFit
    Rows(41).EntireRow.AutoFit
    Rows(42).EntireRow.AutoFit
    Rows(43).EntireRow.AutoFit
    Rows(44).EntireRow.AutoFit
    Rows(45).EntireRow.AutoFit
    Rows(46).EntireRow.AutoFit
    Rows(47).EntireRow.AutoFit
    Rows(48).EntireRow.AutoFit
    Rows(49).EntireRow.AutoFit
    Rows(50).EntireRow.AutoFit
    Rows(51).EntireRow.AutoFit
    Rows(52).EntireRow.AutoFit
    Rows(53).EntireRow.AutoFit
    Rows(54).EntireRow.AutoFit
    Range("A17:A54").EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
vậy cái số "17" trong đoạn code
Mã:
Private Const FitRows As String = "17"
có cần không vậy ạ?
 
Upvote 0
vậy cái số "17" trong đoạn code
Mã:
Private Const FitRows As String = "17"
có cần không vậy ạ?

Bạn có thể hiểu như sau

Rows("17") tương đương với Rows("17").EntireRow
Vì vậy không cần .EntireRow
EntireRow là lấy nguyên cả một hàng hoặc một khối hàng của một Range
Hàng:
Range("A1").EntireRow hoặc Range("A1:A100").EntireRow
Cột:
Range("C6").EntireColumn hoặc Range("A1:Z100").EntireColumn

Rows("17") tức là Dòng thứ 17 trong Trang tính

Rows("17:50").AutoFit

Với Columns thì phải dùng chữ cái, nếu không dùng EntireColumn
Columns("A").AutoFit hoặc Columns("A:ZZ").AutoFit
 
Upvote 0
Bạn có thể hiểu như sau

Rows("17") tương đương với Rows("17").EntireRow
Vì vậy không cần .EntireRow
EntireRow là lấy nguyên cả một hàng hoặc một khối hàng của một Range
Hàng:
Range("A1").EntireRow hoặc Range("A1:A100").EntireRow
Cột:
Range("C6").EntireColumn hoặc Range("A1:Z100").EntireColumn

Rows("17") tức là Dòng thứ 17 trong Trang tính

Rows("17:50").AutoFit

Với Columns thì phải dùng chữ cái, nếu không dùng EntireColumn
Columns("A").AutoFit hoặc Columns("A:ZZ").AutoFit
Rất cám ơn anh!
Vậy mình có thể bỏ đi
Private Const FitRows As String = "17"
trong đoạn code vẫn chạy được đúng không anh?
Nó được thay bởi dòng code "Rows(17).EntireRow.AutoFit"
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(17).EntireRow.AutoFit
    Rows(18).EntireRow.AutoFit
    Rows(19).EntireRow.AutoFit
    Rows(20).EntireRow.AutoFit
    Rows(21).EntireRow.AutoFit
    Rows(22).EntireRow.AutoFit
    Rows(23).EntireRow.AutoFit
    Rows(24).EntireRow.AutoFit
    Rows(25).EntireRow.AutoFit
    Rows(26).EntireRow.AutoFit
    Rows(28).EntireRow.AutoFit
    Rows(29).EntireRow.AutoFit
    Rows(30).EntireRow.AutoFit
    Rows(31).EntireRow.AutoFit
    Rows(32).EntireRow.AutoFit
    Rows(33).EntireRow.AutoFit
    Rows(34).EntireRow.AutoFit
    Rows(35).EntireRow.AutoFit
    Rows(36).EntireRow.AutoFit
    Rows(37).EntireRow.AutoFit
    Rows(38).EntireRow.AutoFit
    Rows(39).EntireRow.AutoFit
    Rows(40).EntireRow.AutoFit
    Rows(41).EntireRow.AutoFit
    Rows(42).EntireRow.AutoFit
    Rows(43).EntireRow.AutoFit
    Rows(44).EntireRow.AutoFit
    Rows(45).EntireRow.AutoFit
    Rows(46).EntireRow.AutoFit
    Rows(47).EntireRow.AutoFit
    Rows(48).EntireRow.AutoFit
    Rows(49).EntireRow.AutoFit
    Rows(50).EntireRow.AutoFit
    Rows(51).EntireRow.AutoFit
    Rows(52).EntireRow.AutoFit
    Rows(53).EntireRow.AutoFit
    Rows(54).EntireRow.AutoFit
    Range("A17:A54").EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Rất cám ơn anh!
Vậy mình có thể bỏ đi
Private Const FitRows As String = "17"
trong đoạn code vẫn chạy được đúng không anh?
Nó được thay bởi dòng code "Rows(17).EntireRow.AutoFit"
Mã:
Private Const FitRows As String = "17"
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Rows(17).EntireRow.AutoFit
    Rows(18).EntireRow.AutoFit
    Rows(19).EntireRow.AutoFit
    Rows(20).EntireRow.AutoFit
    Rows(21).EntireRow.AutoFit
    Rows(22).EntireRow.AutoFit
    Rows(23).EntireRow.AutoFit
    Rows(24).EntireRow.AutoFit
    Rows(25).EntireRow.AutoFit
    Rows(26).EntireRow.AutoFit
    Rows(28).EntireRow.AutoFit
    Rows(29).EntireRow.AutoFit
    Rows(30).EntireRow.AutoFit
    Rows(31).EntireRow.AutoFit
    Rows(32).EntireRow.AutoFit
    Rows(33).EntireRow.AutoFit
    Rows(34).EntireRow.AutoFit
    Rows(35).EntireRow.AutoFit
    Rows(36).EntireRow.AutoFit
    Rows(37).EntireRow.AutoFit
    Rows(38).EntireRow.AutoFit
    Rows(39).EntireRow.AutoFit
    Rows(40).EntireRow.AutoFit
    Rows(41).EntireRow.AutoFit
    Rows(42).EntireRow.AutoFit
    Rows(43).EntireRow.AutoFit
    Rows(44).EntireRow.AutoFit
    Rows(45).EntireRow.AutoFit
    Rows(46).EntireRow.AutoFit
    Rows(47).EntireRow.AutoFit
    Rows(48).EntireRow.AutoFit
    Rows(49).EntireRow.AutoFit
    Rows(50).EntireRow.AutoFit
    Rows(51).EntireRow.AutoFit
    Rows(52).EntireRow.AutoFit
    Rows(53).EntireRow.AutoFit
    Rows(54).EntireRow.AutoFit
    Range("A17:A54").EntireRow.AutoFit
    Application.ScreenUpdating = True
End Sub
1573549932145.png
 
Upvote 0
Web KT
Back
Top Bottom