Not sure if this is what your meaning or not
Option Explicit
Sub freevsaccupied()
Dim ws As Worksheet, ws2 As Worksheet, wsMaster As Worksheet
Dim rngNum As Range, cellPtr As Range
Dim FoundCell As Range
Dim LastRow As Long, iCol As Long
Dim arrResults() As Variant
Set wsMaster = Worksheets("All numbers")
Set ws = Worksheets("Internal numbers")
Set ws2 = Worksheets("Internal Data")
LastRow = GetLastRow(CStr(wsMaster.Name), "A")
Set rngNum = wsMaster.Range("A2:A" & LastRow)
ReDim arrResults(1 To 5, 1 To 1)
For Each cellPtr In rngNum
LastRow = GetLastRow(CStr(ws.Name), "A")
Set FoundCell = ws.Range("A2:A" & LastRow).Find(What:=cellPtr.Value, LookAt:=xlWhole)
If Not FoundCell Is Nothing Then
wsMaster.Cells(cellPtr.Row, "E") = "OCCUPIED"
For iCol = 1 To 5
arrResults(iCol, UBound(arrResults, 2)) = wsMaster.Cells(cellPtr.Row, iCol)
Next
ReDim Preserve arrResults(1 To 5, 1 To UBound(arrResults, 2) + 1)
Else
wsMaster.Cells(cellPtr.Row, "E") = "FREE"
End If
Set FoundCell = Nothing
LastRow = GetLastRow(CStr(ws2.Name), "A")
Set FoundCell = ws2.Range("A2:A" & LastRow).Find(What:=cellPtr.Value, LookAt:=xlWhole)
If Not FoundCell Is Nothing Then
ws2.Range("A" & FoundCell.Row, "AX" & FoundCell.Row).Copy wsMaster.Cells(cellPtr.Row, "F")
End If
Next cellPtr
Worksheets("Results_found").Cells.Delete
arrResults = WorksheetFunction.Transpose(arrResults)
Worksheets("Results_found").Range("A2").Resize(UBound(arrResults), UBound(arrResults, 2)) = arrResults
Erase arrResults
arrResults = wsMaster.Range("A1:E1")
Worksheets("Results_found").Range("A1:E1") = arrResults
Erase arrResults
Set wsMaster = Nothing
Set ws = Nothing
Set rngNum = Nothing
Set cellPtr = Nothing
Set FoundCell = Nothing
End Sub
Private Function GetLastRow(WhatSheet As String, WhatColumn As String) As Long
If Application.Version <= 11 Then
GetLastRow = Worksheets(WhatSheet).Cells(Rows.Count, WhatColumn).End(xlUp).Row
Else
GetLastRow = Worksheets(WhatSheet).Cells(Rows.CountLarge, WhatColumn).End(xlUp).Row
End If
End Function
Bookmarks