I cannot for the life of me, see why I am getting a 'Next without for' compile error for this.
Can anyone throw some light on what I am not seeing here? There is clearly something I have stuffed up.
'If at first you don't succeed, then your hammer is below specifications'
Can anyone throw some light on what I am not seeing here? There is clearly something I have stuffed up.
Code:
For X = 1 To UBound(Z)
Set Bk = Workbooks.Open(Z(X))
On Error Resume Next
Set Sh1 = Bk.Worksheets(Sheet2) ' The data source sheet in the source report
On Error GoTo 0
If Not Sh1 Is Nothing Then
Set rng = Sh1.Range("I5") 'Name
Set rng1 = Sh.Cells(Rows.Count, 1).End(xlUp)(2)
If rng = "" Then
rng = "N/K"
rng1.Copy
rng1.PasteSpecial xlValues
Else
rng.Copy
rng1.PasteSpecial xlValues
End If
Set rng = Sh1.Range("I6") 'DOB
Set rng1 = Sh.Cells(Rows.Count, 2).End(xlUp)(2)
If rng = "" Then
rng = "N/K"
rng1.Copy
rng1.PasteSpecial xlValues
Else
rng.Copy
rng1.PasteSpecial xlValues
End If
Set rng = Sh1.Range("I8") 'Nationality
Set rng1 = Sh.Cells(Rows.Count, 3).End(xlUp)(2)
If rng = "" Then
rng = "N/K"
rng1.Copy
rng1.PasteSpecial xlValues
Else
rng.Copy
rng1.PasteSpecial xlValues
End If
Bk.Close
Next X
'If at first you don't succeed, then your hammer is below specifications'