maiban1986
Thành viên thường trực
- Tham gia
- 28/2/13
- Bài viết
- 229
- Được thích
- 29
chào anh chị. em đang dùng đoạn vba dưới, mỗi lần sử dụng dẫn đến file chạy rất chậm. nhờ anh chị có cách nào tối ưu đoạn vba dưới không. em xin cảm ơn
Sub GhepTextMulVung(Data, Vung As Range)
Dim avKQ()
Dim lngIndex As Long
Dim v
Dim lngNum As Long
Dim rngVung As Range, lngRowKQ As Long, lngRowData As Long, lngRowDataMax As Long
lngRowData = LBound(Data, 1) - 1
lngRowDataMax = UBound(Data)
For Each rngVung In Vung.Areas
If rngVung.Rows.Count = 1 Then
ReDim avKQ(1 To 1, 1 To 1)
Else
ReDim avKQ(1 To rngVung.Rows.Count, 1 To 1)
End If
For lngRowKQ = 1 To UBound(avKQ)
lngRowData = lngRowData + 1
If lngRowData > lngRowDataMax Then
Exit For
Else
avKQ(lngRowKQ, 1) = Data(lngRowData, 1)
End If
Next
rngVung.Value = avKQ
Next rngVung
End Sub
Sub GhepTextMulVung(Data, Vung As Range)
Dim avKQ()
Dim lngIndex As Long
Dim v
Dim lngNum As Long
Dim rngVung As Range, lngRowKQ As Long, lngRowData As Long, lngRowDataMax As Long
lngRowData = LBound(Data, 1) - 1
lngRowDataMax = UBound(Data)
For Each rngVung In Vung.Areas
If rngVung.Rows.Count = 1 Then
ReDim avKQ(1 To 1, 1 To 1)
Else
ReDim avKQ(1 To rngVung.Rows.Count, 1 To 1)
End If
For lngRowKQ = 1 To UBound(avKQ)
lngRowData = lngRowData + 1
If lngRowData > lngRowDataMax Then
Exit For
Else
avKQ(lngRowKQ, 1) = Data(lngRowData, 1)
End If
Next
rngVung.Value = avKQ
Next rngVung
End Sub