brachiosaurus
Thành viên mới
- Tham gia
- 15/6/17
- Bài viết
- 30
- Được thích
- 5
- Giới tính
- Nữ
Chào mọi người!
Mình đang có nhu cầu như sau:
Tại sheet Main
- Copy dữ liệu từ khoảng C18:C63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng I18:I63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng O18:O63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng U18:U63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AA18:AA63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AG18:AG63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AM18:AM63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AS18:AS63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AY18:AY63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng BE18:BE63 đến khi hết dữ liệu
Tất cả copy sang sheet Ngay, dữ liệu sau liền tiếp dữ liệu trước, ko có khoảng cách.
Nhưng hiện tại mình bị vướng các vấn đề sau:
- Code chạy hay lỗi, đơ excel phải tắt toàn bộ đi bật lại, nếu ko lỗi code chạy khá nhanh
- Nếu dữ liệu chạy dài từ cột C đến cột H thì đoạn dữ liệu ở khoảng I sẽ bị copy 2 lần
Code của mình như sau:
Private Sub copyluot1()
Sheets("ngay").Select
Dim lastcol As Integer
With ActiveSheet
lastcol = .Cells(6, .Columns.Count).End(xlToLeft).Column
End With
Application.ScreenUpdating = False
Sheets("Main").Select
Range("C18:C63").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Ngay").Select
If Sheets("ngay").Cells(6, 3).Value = "" Then '3 booth
Sheets("Ngay").Select
Range("C6").Select
Selection.End(xlToRight).Select
Range("c6").PasteSpecial xlPasteValues
ElseIf Sheets("ngay").Cells(6, 3).Value <> "" Then '3 booth
Sheets("Ngay").Select
Cells(6, lastcol + 1).PasteSpecial xlPasteValues
End If
Application.CutCopyMode = False
Sheets("Ngay").Select
Range("B5").Select
If Sheets("main").Cells(18, 9) <> "" Then
copyluot2
End If
End Sub
Sau mỗi khoảng lại thêm 1 sub
Mình mới mày mò VBA nên ko biết nhiều, xin mọi ng trợ giúp ạ. Mình cảm ơn
Mình đang có nhu cầu như sau:
Tại sheet Main
- Copy dữ liệu từ khoảng C18:C63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng I18:I63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng O18:O63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng U18:U63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AA18:AA63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AG18:AG63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AM18:AM63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AS18:AS63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng AY18:AY63 đến khi hết dữ liệu
- Copy dữ liệu từ khoảng BE18:BE63 đến khi hết dữ liệu
Tất cả copy sang sheet Ngay, dữ liệu sau liền tiếp dữ liệu trước, ko có khoảng cách.
Nhưng hiện tại mình bị vướng các vấn đề sau:
- Code chạy hay lỗi, đơ excel phải tắt toàn bộ đi bật lại, nếu ko lỗi code chạy khá nhanh
- Nếu dữ liệu chạy dài từ cột C đến cột H thì đoạn dữ liệu ở khoảng I sẽ bị copy 2 lần
Code của mình như sau:
Private Sub copyluot1()
Sheets("ngay").Select
Dim lastcol As Integer
With ActiveSheet
lastcol = .Cells(6, .Columns.Count).End(xlToLeft).Column
End With
Application.ScreenUpdating = False
Sheets("Main").Select
Range("C18:C63").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Ngay").Select
If Sheets("ngay").Cells(6, 3).Value = "" Then '3 booth
Sheets("Ngay").Select
Range("C6").Select
Selection.End(xlToRight).Select
Range("c6").PasteSpecial xlPasteValues
ElseIf Sheets("ngay").Cells(6, 3).Value <> "" Then '3 booth
Sheets("Ngay").Select
Cells(6, lastcol + 1).PasteSpecial xlPasteValues
End If
Application.CutCopyMode = False
Sheets("Ngay").Select
Range("B5").Select
If Sheets("main").Cells(18, 9) <> "" Then
copyluot2
End If
End Sub
Sau mỗi khoảng lại thêm 1 sub
Mình mới mày mò VBA nên ko biết nhiều, xin mọi ng trợ giúp ạ. Mình cảm ơn