jalrs
Active Member
- Joined
- Apr 6, 2022
- Messages
- 300
- Office Version
- 365
- Platform
- Windows
Hello guys,
Not sure if this is the right approach, but I think so.
I'm needing to add "On Error Resume Next" line to my code, so if it doesn't read the file with folha2.cells(i,5).value on the location, it resumes next i value. I just don't know where.
If this is not the right approach, feel free to suggest any other.
Here is my code:
Any additional question feel free to ask
Any help is greatly appreciated.
Thanks!
Not sure if this is the right approach, but I think so.
I'm needing to add "On Error Resume Next" line to my code, so if it doesn't read the file with folha2.cells(i,5).value on the location, it resumes next i value. I just don't know where.
If this is not the right approach, feel free to suggest any other.
Here is my code:
VBA Code:
Option Explicit
Sub integrarf1()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim livro1 As Workbook, livro2 As Workbook
Dim folha1 As Worksheet, folha2 As Worksheet, folha3 As Worksheet, folha4 As Worksheet
Dim ultimalinha1 As Long, ultimalinha2 As Long, ultimalinha3 As Long, ultimalinha4 As Long, ultimalinha5 As Long, ultimalinha6 As Long, ultimalinha7 As Long, i As Long
Dim localizacao As String, nomedocumento As String, valorfiltro As String
Set livro1 = ThisWorkbook
Set folha1 = livro1.Worksheets("PainelControlo")
Set folha2 = livro1.Worksheets("MACRO 1")
Set folha3 = livro1.Worksheets("Tipificação Feedback")
folha2.Activate
ultimalinha1 = folha2.Cells(Rows.Count, "E").End(xlUp).Row
For i = 2 To ultimalinha1
valorfiltro = Cells(i, 5).Value
ultimalinha2 = folha3.Cells(Rows.Count, "B").End(xlUp).Row + 1
ultimalinha3 = folha3.Cells(Rows.Count, "C").End(xlUp).Row + 1
ultimalinha4 = folha3.Cells(Rows.Count, "D").End(xlUp).Row + 1
Workbooks.Open Filename:=ThisWorkbook.Path & "\Controlo e Difusão\Feedbacks Recebidos\" & Cells(i, 5).Value & ".xlsx"
Set livro2 = Workbooks("" & valorfiltro & ".xlsx")
Set folha4 = livro2.Worksheets("Pendentes")
ultimalinha5 = folha4.Cells(Rows.Count, "D").End(xlUp).Row + 1
ultimalinha6 = folha4.Cells(Rows.Count, "AT").End(xlUp).Row + 1
ultimalinha7 = folha4.Cells(Rows.Count, "AX").End(xlUp).Row + 1
With folha4
.Range("D2:D" & ultimalinha5).Copy
folha3.Cells(ultimalinha2, 2).PasteSpecial Paste:=xlPasteValues
.Range("AT2:AT" & ultimalinha6).Copy
folha3.Cells(ultimalinha3, 3).PasteSpecial Paste:=xlPasteValues
.Range("AX2:AZ" & ultimalinha7).Copy
folha3.Cells(ultimalinha4, 4).PasteSpecial Paste:=xlPasteValues
End With
ActiveWorkbook.Close
Application.CutCopyMode = False
folha2.Activate
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Any additional question feel free to ask
Any help is greatly appreciated.
Thanks!