Sub CopyAndPasteCabinCrewActualArray()
Dim firstRow As Integer, StartAt As Integer, i As Integer
Dim NoOfCrew As Long
Dim firstNameArray(), lastNameArray(), genderArray(), RankArray(), passportNoArray()
Dim HotelBooking As Worksheet
Set HotelBooking = ThisWorkbook.Worksheets("Hotel Booking")
firstRow = 10
NoOfCrew = 0
NoOfCrew = HotelBooking.Cells(Rows.Count, "A").End(xlUp).Row
NoOfCrew = NoOfCrew - 9
StartAt = firstRow - 1
If NoOfCrew = 1 Then
Dim firstName As String, lastName As String, gender As String, Rank As String, passportNo As String
With HotelBooking
firstName = .Cells(firstRow, 1)
lastName = .Cells(firstRow, 2)
gender = .Cells(firstRow, 3)
Rank = .Cells(firstRow, 4)
passportNo = .Cells(firstRow, 5)
HotelBooking.Cells(1 + StartAt, 14).Value = firstName & " " & lastName
HotelBooking.Cells(1 + StartAt, 29).Value = gender
HotelBooking.Cells(1 + StartAt, 32).Value = Rank
HotelBooking.Cells(1 + StartAt, 49).Value = passportNo
End With
Else
With HotelBooking
firstNameArray = Range(.Cells(firstRow, 1), .Cells(NoOfCrew + 9, 1))
lastNameArray = Range(.Cells(firstRow, 2), .Cells(NoOfCrew + 9, 2))
genderArray = Range(.Cells(firstRow, 3), .Cells(NoOfCrew + 9, 3))
RankArray = Range(.Cells(firstRow, 4), .Cells(NoOfCrew + 9, 4))
passportNoArray = Range(.Cells(firstRow, 5), .Cells(NoOfCrew + 9, 5))
End With
For i = LBound(firstNameArray) To UBound(lastNameArray)
HotelBooking.Cells(i + StartAt, 14).Value = firstNameArray(i, 1) & " " & lastNameArray(i, 1)
HotelBooking.Cells(i + StartAt, 29).Value = genderArray(i, 1)
HotelBooking.Cells(i + StartAt, 32).Value = RankArray(i, 1)
HotelBooking.Cells(i + StartAt, 49).Value = passportNoArray(i, 1)
Next i
End If
End Sub
It is by far best practice to dimension your variables (especially workbooks and sheets) before use, thus I set a variable for hotelbooking and used it throughout the code.