cunandmickey
Thành viên mới
- Tham gia
- 27/10/23
- Bài viết
- 1
- Được thích
- 0
Chào cả nhà !
Do tính chất công việc nên file excel của em link dữ liệu nhiều file và nhiều công thức nên dẫn đến excel phải xử lý nhiều và chậm
Em có xem trên youtube hướng dẫn làm VBA và ghi lại mã code sau
Nhưng khi chạy bị báo lỗi vì có khúc sau 1 vài dòng e tự mò ghi ra
Cả nhà xem size chỗ nào chỉnh giúp em với
Sub AR_Excel_SpeedUp()
Application.ScreenUpdating = False
Dim i, j, Lr, Lc As Interger
Dim wSpeed, ws1, ws2, ws3, ws4 As Worksheet
Set wSpeed = Worksheets("SpeedUp")
Lr = wSpeed.Cells(Row.Count, "A").End(x1Up).Row
Lc = wSpeed.Cells(5, wSpeed.Column.Count).End(x1ToLeft).Column
'On Error GoTo AR_Alert
wSpeed.Ranger("A1") = ActiveSheet.Name
If wSpeed.Range("B1").Value > 0 Then
If UCase(wSpeed.Range("J1").Value) = "MANUAL" And wSpeed.Range("K1").Value Mod 2 Then '// Manual input formula in Column
wSpeed.Range("K1") = wSpeed.Range("K1").Value + 1
For i = 4 To Lr
If UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "Column" Then
For j = 3 To Lc Step 3
ActiveSheet.Range(ActiceSheet.Cells(wSpeed.Cells(i, j).Value, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value)) = "Column"
Next
ElseIf UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, j).Value) And UCase(wSpeed.Cells(i, 2)) = "ROW" Then '// Manual input Formula in Row
ActiveSheet.Range(AtiveSheet.Cells(wSpeed.Cells(i, "C").Value, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E"), Value + 1, wSpeed.Range("J1"))) = "Row"
End If
Next
Application.Assitant.DoAlert "AR Excal VBA", "Formula is Copied", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
ElseIf UCase(wSpeed.Range("J1").Value) = "MUNAL" And Not wSpeed.Range("K1").Value Mod 2 Then ''//Manual Return value in Column
wSpeed.Range("K1") = wSpeed.Range("K1").Value + 1
For i = 4 To Lr
If UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "COLUMN" Then
For j = 3 To Lc Step 3
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, j).Value + 1, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value)) = "Column"
Next
ElseIf UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "ROW" Then '// Manual input Formula in Row
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, "C").Value + 1, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E").Value + 1, wSpeed.Range("K1"))) = "Row"
End If
Next
Application.Assistant.DoAlert "AR Excell VBA", "Value is Returned", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
ElseIf UCase(wSpeed.Range("J1")) = "AUTO" Then
For i = 4 To Lr
For j = 3 To Lc Step 3
If UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "COLUMN" Then
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, j).Value, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value, wSpeed.Cells(i, j + 1).Value)) = "COLUMN"
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, j).Value + 1, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value)) = "COLUMN"
ElseIf UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "ROW" Then
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, "C").Value, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E").Value, wSpeed.Cells(i, j + 1).Value)) = "ROW"
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, "C").Value + 1, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E").Value)) = "ROW"
End If
Next
Next
Apllication.Assitant.DoAlert "AR Excell VBA", "Data is Updated", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
End If
Else
Apllication.Assitant.DoAlert "AR Excell VBA", "Sheet name is wrong", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
End If
End Sub
hình ảnh lỗi không chạy dc và báo vàng như hình
Do tính chất công việc nên file excel của em link dữ liệu nhiều file và nhiều công thức nên dẫn đến excel phải xử lý nhiều và chậm
Em có xem trên youtube hướng dẫn làm VBA và ghi lại mã code sau
Nhưng khi chạy bị báo lỗi vì có khúc sau 1 vài dòng e tự mò ghi ra
Cả nhà xem size chỗ nào chỉnh giúp em với
Sub AR_Excel_SpeedUp()
Application.ScreenUpdating = False
Dim i, j, Lr, Lc As Interger
Dim wSpeed, ws1, ws2, ws3, ws4 As Worksheet
Set wSpeed = Worksheets("SpeedUp")
Lr = wSpeed.Cells(Row.Count, "A").End(x1Up).Row
Lc = wSpeed.Cells(5, wSpeed.Column.Count).End(x1ToLeft).Column
'On Error GoTo AR_Alert
wSpeed.Ranger("A1") = ActiveSheet.Name
If wSpeed.Range("B1").Value > 0 Then
If UCase(wSpeed.Range("J1").Value) = "MANUAL" And wSpeed.Range("K1").Value Mod 2 Then '// Manual input formula in Column
wSpeed.Range("K1") = wSpeed.Range("K1").Value + 1
For i = 4 To Lr
If UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "Column" Then
For j = 3 To Lc Step 3
ActiveSheet.Range(ActiceSheet.Cells(wSpeed.Cells(i, j).Value, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value)) = "Column"
Next
ElseIf UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, j).Value) And UCase(wSpeed.Cells(i, 2)) = "ROW" Then '// Manual input Formula in Row
ActiveSheet.Range(AtiveSheet.Cells(wSpeed.Cells(i, "C").Value, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E"), Value + 1, wSpeed.Range("J1"))) = "Row"
End If
Next
Application.Assitant.DoAlert "AR Excal VBA", "Formula is Copied", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
ElseIf UCase(wSpeed.Range("J1").Value) = "MUNAL" And Not wSpeed.Range("K1").Value Mod 2 Then ''//Manual Return value in Column
wSpeed.Range("K1") = wSpeed.Range("K1").Value + 1
For i = 4 To Lr
If UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "COLUMN" Then
For j = 3 To Lc Step 3
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, j).Value + 1, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value)) = "Column"
Next
ElseIf UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "ROW" Then '// Manual input Formula in Row
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, "C").Value + 1, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E").Value + 1, wSpeed.Range("K1"))) = "Row"
End If
Next
Application.Assistant.DoAlert "AR Excell VBA", "Value is Returned", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
ElseIf UCase(wSpeed.Range("J1")) = "AUTO" Then
For i = 4 To Lr
For j = 3 To Lc Step 3
If UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "COLUMN" Then
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, j).Value, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value, wSpeed.Cells(i, j + 1).Value)) = "COLUMN"
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, j).Value + 1, wSpeed.Cells(i, j + 2).Value), ActiveSheet.Cells(wSpeed.Cells(i, j + 1).Value)) = "COLUMN"
ElseIf UCase(ActiveSheet.Name) = UCase(wSpeed.Cells(i, 1).Value) And UCase(wSpeed.Cells(i, 2)) = "ROW" Then
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, "C").Value, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E").Value, wSpeed.Cells(i, j + 1).Value)) = "ROW"
ActiveSheet.Range(ActiveSheet.Cells(wSpeed.Cells(i, "C").Value + 1, wSpeed.Cells(i, "D").Value), ActiveSheet.Cells(wSpeed.Cells(i, "E").Value)) = "ROW"
End If
Next
Next
Apllication.Assitant.DoAlert "AR Excell VBA", "Data is Updated", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
End If
Else
Apllication.Assitant.DoAlert "AR Excell VBA", "Sheet name is wrong", msoAlertButtonOK, msoAlertIconInfo, 0, 0, 0
End If
End Sub
Bài đã được tự động gộp:
hình ảnh lỗi không chạy dc và báo vàng như hình