Hi,
I would need some help.
I've attached a code and I have 9 of them for each file separately and they are all the same, only thing that differs is a name of file that each code should enter and the name of macro. The name of file is a name of brand manager which is also a name of each macro. E.g. code:
The main problem is if there is no e.g. file SANDRA that macro SANDRA should enter, the code breaks. How can I fix this - to set a code to skip macro if its file is missing.
Thnx a lot
I would need some help.
I've attached a code and I have 9 of them for each file separately and they are all the same, only thing that differs is a name of file that each code should enter and the name of macro. The name of file is a name of brand manager which is also a name of each macro. E.g. code:
Code:
Sub Sandra()
Dim wkb As Workbook, wkbFrom As Workbook
Dim fromPath As String
fromPath = Sheets("UPUTSTVO").Range("B12")
If Right(fromPath, 1) <> "\" Then fromPath = fromPath & "\"
Set wkb = ThisWorkbook
Application.EnableEvents = False
Set wkbFrom = Workbooks.Open(fromPath & "SANDRA.XLSM")
Windows("SANDRA.xlsm").Activate
Sheets("TABELA").Select
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
Range("A3:O" & lastrow).Select
Selection.Copy
Windows("BAZA.xlsm").Activate
Sheets("TABELA").Select
lastrow1 = Cells(Rows.Count, "E").End(xlUp).Row
Range("A" & lastrow1 + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("SANDRA.xlsm").Activate
Sheets("TABELA").Select
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
Range("W3:AN" & lastrow).Select
Selection.Copy
Windows("BAZA.xlsm").Activate
Sheets("TABELA").Select
lastrow1 = Cells(Rows.Count, "E").End(xlUp).Row
Range("W" & lastrow1 - lastrow + 3).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Windows("SANDRA.xlsm").Activate
Sheets("TABELA").Select
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
Range("BG3:BG" & lastrow).Select
Selection.Copy
Windows("BAZA.xlsm").Activate
Sheets("TABELA").Select
lastrow1 = Cells(Rows.Count, "E").End(xlUp).Row
Range("BG" & lastrow1 - lastrow + 3).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Windows("SANDRA.xlsm").Close Saved = False
End Sub
I also made a single code that calls/uses all of these 9 codes to connect with names and you can see that here
Sub Baza()
Call ANJA
Call JELENA_B
Call MILA_I_VESNA
Call MILENA
Call NATASA
Call NEDA
Call NIKOLA
Call RADA
Call SANDRA
End Sub
The main problem is if there is no e.g. file SANDRA that macro SANDRA should enter, the code breaks. How can I fix this - to set a code to skip macro if its file is missing.
Thnx a lot
Last edited by a moderator: