I want to write some vba code that will look up the file name of the active workbook, then search for that filename in the first row of a different workbook, and if it finds it, copy the column its in and paste it to the workbook of that name. The code I have doesn’t work. Can anyone help? Here’s the code using two example spreadsheets:
Dim wbk2 As Workbook
Dim wn2 As String
Dim wn1 As String
Dim dcell As Range
Dim drange As Range
wn1 = ActiveWorkbook.name ' 036.xls
wn2 = "Lookupspreadsheet.xls"
Set wbk2 = Workbooks.Open(wn2)
Set drange = Sheets("sheet1").Range("A1:A10")
For Each dcell In drange
If dcell = wn1 Then
Range("A" & dcell).EntireColumn.Select
Selection.copy
Workbooks(wn1).Sheets("before").Activate
Range("A:A”).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("before").Range("A:A").NumberFormat = "hh:mm:ss"
End If
Next dcell
thanks
Bookmarks