Chào mọi người trên GPE,
Em có vấn đề muốn nhờ mọi người giúp đỡ trong việc cải tiến tốc độ xử lý code VBA câu lệnh trên Excel
Em có viết câu lệnh trên VBA các lệnh excel, sau đó chỉ lấy giá trị của nó (bỏ công thức đi để file excel nhẹ, dễ mở khi dữ liệu điền vào lớn)
Tuy nhiên e chạy VBA thấy load chậm quá, nhờ mọi người giúp có cách gì khác để xử lý bài toán này không?
VBA này e dùng record macro + chế thêm
Em có vấn đề muốn nhờ mọi người giúp đỡ trong việc cải tiến tốc độ xử lý code VBA câu lệnh trên Excel
Em có viết câu lệnh trên VBA các lệnh excel, sau đó chỉ lấy giá trị của nó (bỏ công thức đi để file excel nhẹ, dễ mở khi dữ liệu điền vào lớn)
Tuy nhiên e chạy VBA thấy load chậm quá, nhờ mọi người giúp có cách gì khác để xử lý bài toán này không?
VBA này e dùng record macro + chế thêm
Mã:
Sub rundata()
On Error Resume Next
Dim i As Long, lr As Long
'Sheets("BDL").Range("A6:BH9999").Borders.LineStyle = 0
lr = Sheets("BDL").Cells(Sheets("BDL").Rows.Count, "A").End(xlUp).Row
If lr <= 4 Then
MsgBox "Chua co du lieu"
Exit Sub
End If
With Sheets("BDL")
For i = 5 To lr
If .Range("BH" & i).Value = "" Then
.Range("X" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-23]&""_""&DAY(RC[-10])&MONTH(RC[-10]),'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]BrDau'!R3C1:R999999C5,5,0),"""")"
.Range("X" & i) = .Range("X" & i).Value
.Range("y" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-24]&""_""&DAY(RC[-11])&MONTH(RC[-11]),'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]BrGiua'!R3C1:R999999C5,5,0),"""")"
.Range("y" & i) = .Range("Y" & i).Value
.Range("z" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-25]&""_""&DAY(RC[-12])&MONTH(RC[-12]),'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]BrCuoi'!R3C1:R999999C5,5,0),"""")"
.Range("z" & i) = .Range("Z" & i).Value
.Range("AF" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-31]&""_""&DAY(RC[-18])&MONTH(RC[-18])&""_""&1,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AF" & i) = .Range("AF" & i).Value
.Range("AG" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-32]&""_""&DAY(RC[-19])&MONTH(RC[-19])&""_""&2,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AG" & i) = .Range("AG" & i).Value
.Range("AH" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-33]&""_""&DAY(RC[-20])&MONTH(RC[-20])&""_""&3,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AH" & i) = .Range("AH" & i).Value
.Range("AI" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-34]&""_""&DAY(RC[-21])&MONTH(RC[-21])&""_""&4,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AI" & i) = .Range("AI" & i).Value
.Range("AJ" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-35]&""_""&DAY(RC[-22])&MONTH(RC[-22])&""_""&5,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AJ" & i) = .Range("AJ" & i).Value
.Range("AK" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-36]&""_""&DAY(RC[-23])&MONTH(RC[-23])&""_""&6,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AK" & i) = .Range("AK" & i).Value
.Range("AL" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-37]&""_""&DAY(RC[-24])&MONTH(RC[-24])&""_""&7,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AL" & i) = .Range("AL" & i).Value
.Range("AM" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-38]&""_""&DAY(RC[-25])&MONTH(RC[-25])&""_""&8,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AM" & i) = .Range("AM" & i).Value
.Range("AN" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-39]&""_""&DAY(RC[-26])&MONTH(RC[-26])&""_""&9,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AN" & i) = .Range("AN" & i).Value
.Range("AO" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-40]&""_""&DAY(RC[-27])&MONTH(RC[-27])&""_""&10,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AO" & i) = .Range("AO" & i).Value
.Range("AP" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-41]&""_""&DAY(RC[-28])&MONTH(RC[-28])&""_""&11,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AP" & i) = .Range("AP" & i).Value
.Range("AQ" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-42]&""_""&DAY(RC[-29])&MONTH(RC[-29])&""_""&12,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AQ" & i) = .Range("AQ" & i).Value
.Range("AR" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-43]&""_""&DAY(RC[-30])&MONTH(RC[-30])&""_""&13,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AR" & i) = .Range("AR" & i).Value
.Range("AS" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-44]&""_""&DAY(RC[-31])&MONTH(RC[-31])&""_""&14,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AS" & i) = .Range("AS" & i).Value
.Range("AT" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-45]&""_""&DAY(RC[-32])&MONTH(RC[-32])&""_""&15,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AT" & i) = .Range("AT" & i).Value
.Range("AU" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-46]&""_""&DAY(RC[-33])&MONTH(RC[-33])&""_""&16,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]SoBinh'!R3C1:R999999C3,3,0),"""")"
.Range("AU" & i) = .Range("AU" & i).Value
.Range("AV" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-25]&""_""&DAY(RC[-34])&MONTH(RC[-34])&""_""&1,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,5,0),"""")"
.Range("AV" & i) = .Range("AV" & i).Value
.Range("AW" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-26]&""_""&DAY(RC[-35])&MONTH(RC[-35])&""_""&1,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,6,0),"""")"
.Range("AW" & i) = .Range("AW" & i).Value
.Range("AY" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-28]&""_""&DAY(RC[-37])&MONTH(RC[-37])&""_""&2,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,5,0),"""")"
.Range("AY" & i) = .Range("AY" & i).Value
.Range("AZ" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-29]&""_""&DAY(RC[-38])&MONTH(RC[-38])&""_""&2,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,6,0),"""")"
.Range("AZ" & i) = .Range("AZ" & i).Value
.Range("BB" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-31]&""_""&DAY(RC[-40])&MONTH(RC[-40])&""_""&3,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,5,0),"""")"
.Range("BB" & i) = .Range("BB" & i).Value
.Range("BC" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-32]&""_""&DAY(RC[-41])&MONTH(RC[-41])&""_""&3,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,6,0),"""")"
.Range("BC" & i) = .Range("BC" & i).Value
.Range("BE" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-34]&""_""&DAY(RC[-43])&MONTH(RC[-43])&""_""&4,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,5,0),"""")"
.Range("BE" & i) = .Range("BE" & i).Value
.Range("BF" & i).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-35]&""_""&DAY(RC[-44])&MONTH(RC[-44])&""_""&4,'\\192.168.14.1\Honglam2019\SanXuat\9.P2_PX1\2019\SC_TDD_2019\[NhapLieu_TDSau.xlsb]DichDu'!R3C1:R999999C7,6,0),"""")"
.Range("BF" & i) = .Range("BF" & i).Value
.Range("AA" & i).FormulaR1C1 = "=COUNTA(RC[5]:RC[20])-COUNTBLANK(RC[5]:RC[20])"
.Range("AA" & i) = .Range("AA" & i).Value
.Range("AB" & i).FormulaR1C1 = "=IF(RC[-1]<>"""",RC[-1]*13,"""")"
.Range("AB" & i) = .Range("AB" & i).Value
End If
Next
End With
Sheets("BDL").Range("A5:BH" & lr + 1).Borders.LineStyle = 1
Sheets("BDL").Range("A" & lr + 1).Select
End Sub