+ Reply to Thread
Results 1 to 2 of 2

Copying multiple rows from different spreadsheet based on a logic

Hybrid View

  1. #1
    Registered User
    Join Date
    12-23-2006
    Posts
    2

    Copying multiple rows from different spreadsheet based on a logic

    Dear Friends, Need your help in the following :

    Here is my requirement:

    I have a worksheet which has columns 1,3,6,8. Which has few rows with a unique values in column 1.

    I get a spreadsheet everyday with columns 1,2,3,4,5,6,7,8,9,10.

    I need to insert new rows with only columns 1,3,6,8.

    I need a button using which I should be able to update. It would be great if the macro gives me an option of selecting the file.

    Thanks in advance.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this macro

    Option Explicit
    
    Sub InportData()
    Dim sFile As String
    Dim wsD As Worksheet
    Dim wsP As Worksheet
    Dim lRowD As Long
    Dim lRowP As Long
    
    Set wsP = ThisWorkbook.Sheets("sheet1")
    
    sFile$ = Application _
        .GetOpenFilename("Excel_Files (*.xls), *.xls")
    Workbooks.Open Filename:=sFile
    Set wsD = ActiveSheet
    
    lRowD = wsD.Cells.Find(what:="*", searchorder:=xlByRows, _
    searchdirection:=xlPrevious).Row
    lRowP = wsP.Cells.Find(what:="*", searchorder:=xlByRows, _
    searchdirection:=xlPrevious).Row + 1
    
    wsD.Range("a1:a" & lRowD).Copy wsP.Range("a" & lRowP)
    wsD.Range("c1:c" & lRowD).Copy wsP.Range("c" & lRowP)
    wsD.Range("f1:f" & lRowD).Copy wsP.Range("f" & lRowP)
    wsD.Range("h1:h" & lRowD).Copy wsP.Range("h" & lRowP)
    End Sub
    Last edited by VBA Noob; 12-23-2006 at 03:49 PM.

+ Reply to Thread

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