Public Sub test()
Dim DuLieu, i As Long, lastRow As Long
With Sheets("Du lieu")
lastRow = .Range("H" & Rows.Count).End(xlUp).Row
DuLieu = .Range("H7:H" & lastRow).Value
End With
For i = 1 To UBound(DuLieu, 1)
Sheets("Tong hop").Range("B" & i * 6 - 1) = DuLieu(i, 1)
Next i
End Sub
Tàu của anh Musk hết xăng nên quay về nửa chừng.Tưởng bạn @Let'GâuGâu đi "Sao Hỏa" định cư rồi chứ...![]()
Dạ cám ơn. Đúng ý em rồi ah.@ntg82vn
Dùng thử :
Mã:Public Sub test() Dim DuLieu, i As Long, lastRow As Long With Sheets("Du lieu") lastRow = .Range("H" & Rows.Count).End(xlUp).Row DuLieu = .Range("H7:H" & lastRow).Value End With For i = 1 To UBound(DuLieu, 1) Sheets("Tong hop").Range("B" & i * 6 - 1) = DuLieu(i, 1) Next i End Sub
Phiền thầy 1 chút nữa là làm sao để từ ô B đến ô H nó tự động dùng chức năng "merge & centrer"@ntg82vn
Dùng thử :
Mã:Public Sub test() Dim DuLieu, i As Long, lastRow As Long With Sheets("Du lieu") lastRow = .Range("H" & Rows.Count).End(xlUp).Row DuLieu = .Range("H7:H" & lastRow).Value End With For i = 1 To UBound(DuLieu, 1) Sheets("Tong hop").Range("B" & i * 6 - 1) = DuLieu(i, 1) Next i End Sub
Public Sub test()
Dim DuLieu, i As Long, lastRow As Long
Application.ScreenUpdating = False
With Sheets("Du lieu")
lastRow = .Range("H" & Rows.Count).End(xlUp).Row
DuLieu = .Range("H7:H" & lastRow).Value
End With
With Sheets("Tong hop")
For i = 1 To UBound(DuLieu, 1)
.Range("B" & i * 6 - 1) = DuLieu(i, 1)
.Range("B" & i * 6 - 1).Resize(1, 7).HorizontalAlignment = xlCenterAcrossSelection
.Range("B6:B9").Copy
.Range("B" & i * 6).PasteSpecial Paste:=xlPasteValues
Next i
Application.CutCopyMode = False
End With
Application.ScreenUpdating = True
End Sub
Cám ơn sự góp ý của thầy.Cách làm là theo suy nghĩ của chủ Topic.
Tôi lại nghĩ khác:
- Cột H sheet Du lieu chỉ là 1 phần thông tin.
- Sheet Tong hop lại muốn in nhãn để làm cái gì đó thì chưa biết?
Theo tôi thì chủ Topic cần làm cái gì đó thì nên nêu rõ mục đích, còn giải pháp thì để các thành viên lo có nhiều khi nó hay hơn và tiện lợi hơn.
Không lẽ, có phát sinh thêm thì lại hỏi tiếp, chắc các code nêu trên phá sản quá.
Cám ơn thầy.Bạn chỉ cần nhập Địa chỉ: Họ tên cha ,họ tên mẹ, Lớp đang học từ B6 đến B9 rồi chạy code.
Mã:Public Sub test() Dim DuLieu, i As Long, lastRow As Long Application.ScreenUpdating = False With Sheets("Du lieu") lastRow = .Range("H" & Rows.Count).End(xlUp).Row DuLieu = .Range("H7:H" & lastRow).Value End With With Sheets("Tong hop") For i = 1 To UBound(DuLieu, 1) .Range("B" & i * 6 - 1) = DuLieu(i, 1) .Range("B" & i * 6 - 1).Resize(1, 7).HorizontalAlignment = xlCenterAcrossSelection .Range("B6:B9").Copy .Range("B" & i * 6).PasteSpecial Paste:=xlPasteValues Next i Application.CutCopyMode = False End With Application.ScreenUpdating = True End Sub
Đâu cần 3 dòng này. Chỉ cần:Sheets("Tong hop").Range("B" & i * 6 - 1).Resize(1, 7).Merge
Sheets("Tong hop").Range("B" & i * 6 - 1).Resize(1, 7).HorizontalAlignment = xlCenter
Sheets("Tong hop").Range("B" & i * 6 - 1).Resize(1, 7).VerticalAlignment = xlCenter
là dữ liệu được canh giữa 7 ô bạn chọn..Range("B" & i * 6 - 1).Resize(1, 7).HorizontalAlignment = xlCenterAcrossSelection
Vâng em lại biết thêm "xlCenterAcrossSelection " nữa rồi.Đâu cần 3 dòng này. Chỉ cần:
là dữ liệu được canh giữa 7 ô bạn chọn.