Giúp viết code nối cột A và cột B dữ liệu khoảng 1 triệu dòng

Chia sẻ bởi:hands
★★★★★
Quảng cáo

Chào GPE ! Tồi cần viết 1 đoạn code để nối kết quả cột A và cột B cho ra cột C ( khoảng 1 triệu dòng ). Nhờ anh chỉ diễn đàn giúp đỡ. Xin cảm ơn

137

Sub noiHonMotTrieuDong()
const sRangeData = "A2:B1048500"
const sDelim = " # "
const sCellTarget = "C2"
Dim data as variant, i as long, strA as string, listRes as variant
data = range(sRangeData).value2
redim listRes(1 to ubound(data,1),1 to 1)
For i=1 to ubound(data,1)
strA = data(i,1)
if vba.len(strA)>0 then
listRes(i,1)=strA & sDelim & data(i,2)
End if
Next i
Range(sCellTarget).Resize(ubound(listRes,1),1).value=listRes
erase data, listRes

End sub

www.giaiphapexcel.com/diendan/threads/gi%C3%BAp-vi%E1%BA%BFt-code-n%E1%BB%91i-c%E1%BB%99t-a-v%C3%A0-c%E1%BB%99t-b-d%E1%BB%AF-li%E1%BB%87u-kho%E1%BA%A3ng-1-tri%E1%BB%87u-d%C3%B2ng.163213/post-1088630

Sub VBconcate()
Dim sArr As Variant, dArr As Variant
Dim i As Long
    sArr = Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row)
    ReDim dArr(1 To UBound(sArr))
    For i = 1 To UBound(sArr)
        dArr(i) = sArr(i, 1) & " # " & sArr(i, 2)
    Next i
    Application.Calculation = xlManual
    Range("C1").Resize(UBound(sArr)) = WorksheetFunction.Transpose(dArr)
    Application.Calculation = xlAutomatic
End Sub

Chắc phải vầy quá.
Toàn dữ liệu thần thánh.

www.giaiphapexcel.com/diendan/threads/gi%C3%BAp-vi%E1%BA%BFt-code-n%E1%BB%91i-c%E1%BB%99t-a-v%C3%A0-c%E1%BB%99t-b-d%E1%BB%AF-li%E1%BB%87u-kho%E1%BA%A3ng-1-tri%E1%BB%87u-d%C3%B2ng.163213/post-1088742

Dùng EVALUATE cả cột, sau đó filter để loại bỏ dòng trống
Máy mình chạy khoảng 4s

Option Explicit
Sub NOICOT()
Dim t
t = Timer
With Columns(3)
.Value = Evaluate("=A:A & "" # "" & B:B")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="#"
Rows("2:1048576").Delete Shift:=xlUp
.AutoFilter
End With
MsgBox Timer – t
End Sub

138
www.giaiphapexcel.com/diendan/threads/gi%C3%BAp-vi%E1%BA%BFt-code-n%E1%BB%91i-c%E1%BB%99t-a-v%C3%A0-c%E1%BB%99t-b-d%E1%BB%AF-li%E1%BB%87u-kho%E1%BA%A3ng-1-tri%E1%BB%87u-d%C3%B2ng.163213/post-1088810

Kỹ năng giải quyết vấn đề hiệu quả
Khóa học SprinGO phù hợp

Kỹ năng giải quyết vấn đề hiệu quả

Mô tả Nội dung Đánh giá Tài nguyên KỸ NĂNG GIẢI QUYẾT VẤN ĐỀ HIỆU QUẢHiểu đúng vấn đề là một nửa của giải...

Xem khóa học
★★★★★ 5 ★ 1 👤 0 ▥ 0
Quảng cáo

Bạn nên đọc

Bình luận

Quảng cáo

Cũ vẫn chất

Xem thêm