I think I understand what you mean now.
The range named:"test" is non contiguous that is why I think the code will have to loop and do the pasting one by one.
Here is what I have and it works (but there should be a better way)
Private Function My_Workbook_Open(sFilePath As String) As Workbook
'//Opens a workbook and returns a reference to it
'//Returns Nothing if no workbook of the name exists
On Error Resume Next
Set My_Workbook_Open = Workbooks.Open(sFilePath)
End Function
Sub search()
Application.ScreenUpdating = False
Dim FN As String
FN = Range("B2").Value
Dim FR As String
FR = Range("D2")
'To open
Workbooks.Open (ThisWorkbook.Path & "\depot\" & FN)
Dim c As Range
lookfor = FR
With Sheets("sheet1")
Set c = .Columns(1).Find(What:=lookfor, LookIn:=xlValues, _
LookAt:=xlWhole, MatchCase:=False)
If Not c Is Nothing Then
c.EntireRow.Copy
Workbooks("hello toronto").Activate
Workbooks("hello toronto").Sheets("Search").Range("A1").PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Call test
Else
Workbooks("hello toronto").Activate
MsgBox lookfor & " not found"
End If
End With
Application.ScreenUpdating = True
End Sub
Sub test()
[A24] = [A1]
[B23] = [B1]
[A16] = [C1]
[D20] = [D1]
[E12] = [E1]
[F27] = [F1]
[E16] = [G1]
[A15] = [H1]
[K14] = [I1]
[L20] = [J1]
[P21] = [K1]
[M19] = [L1]
End Sub
Pls note that the sub "test" is incomplete here ... in fact it should be 131 lines long.
ALSO: I have the silly habit of naming all temporary codes AND named ranges "test"
In the file i'm wresling with the named ranged of the non contiguous cells is: test
as well the name of teh sub is also test.
What the code does:
On sheet "shearch" in WB "hello toronto" in cells:
B2 I type the name of a Company
D2 I type an Invoice number
The code looks for a file matching the name in B2 within a folder called "depot"
Then it opens the file and matches value D2 to column A of sheet1 of that file/ copies the whole row(131 cells, with empties or without) comes back to sheet "search" and paste the data in row1
The code that I'm trying to simplify will place each value from Row1 to selected cells (the cells are non contiguous)
Hope I don't confuse you more ... I could attach the whole thing if you want