Results 1 to 1 of 1

search for value in a row, copy column to another spreadsheet

Threaded View

  1. #1
    Registered User
    Join Date
    01-07-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    search for value in a row, copy column to another spreadsheet

    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
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1