+ Reply to Thread
Results 1 to 6 of 6

copy copy row of data to empty row in sheet2

Hybrid View

  1. #1
    Registered User
    Join Date
    06-04-2008
    MS-Off Ver
    2007
    Posts
    37

    copy copy row of data to empty row in sheet2

    hi there,
    i need help with a bit of code:

    i need a macro that searches columns C and E (on sheet1) for any cell with data.
    and if finds data in either C or E, it copies that entire row to sheet2 in the next empty row, and adds a date stamp to column F

    thanx in advance

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try to use this macro:
    Sub Macro1()
        Dim sh1 As Worksheet
        Dim sh2 As Worksheet
        Dim sh1LastRow As Long
        Dim sh2LastRow As Long
        Dim r As Long
        
        Set sh1 = ThisWorkbook.Sheets("sheet1")
        Set sh2 = ThisWorkbook.Sheets("sheet2")
        
        On Error Resume Next
        sh1LastRow = sh1.Cells.Find("*", SearchOrder:=xlByRows, _
                     SearchDirection:=xlPrevious).Row
        sh2LastRow = sh2.Cells.Find("*", SearchOrder:=xlByRows, _
                     SearchDirection:=xlPrevious).Row
        On Error GoTo 0
        
        For r = 1 To sh1LastRow
            If sh1.Cells(r, "c") <> "" Or sh1.Cells(r, "e") <> "" Then
                sh2LastRow = sh2LastRow + 1
                sh1.Rows(r).Copy sh2.Cells(sh2LastRow, "a")
            End If
        Next
    End Sub
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    06-04-2008
    MS-Off Ver
    2007
    Posts
    37

    thanx alot

    havnt tried yet, but code looks really good, only i dont see anywhere the code for the date stamp?

    thanx shy

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    shy07014,


    Cross Post Please read forum rules below about cross posting

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Registered User
    Join Date
    06-04-2008
    MS-Off Ver
    2007
    Posts
    37

    Red face

    sorry, im new i didnt know, just read the rule, thanx for the info.

  6. #6
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    I apologize but I forgot timestamp statement. Here is the new macro:
    Sub Macro1()
        Dim sh1 As Worksheet
        Dim sh2 As Worksheet
        Dim sh1LastRow As Long
        Dim sh2LastRow As Long
        Dim r As Long
        
        Set sh1 = ThisWorkbook.Sheets("sheet1")
        Set sh2 = ThisWorkbook.Sheets("sheet2")
        
        On Error Resume Next
        sh1LastRow = sh1.Cells.Find("*", SearchOrder:=xlByRows, _
                     SearchDirection:=xlPrevious).Row
        sh2LastRow = sh2.Cells.Find("*", SearchOrder:=xlByRows, _
                     SearchDirection:=xlPrevious).Row
        On Error GoTo 0
        
        For r = 1 To sh1LastRow
            If sh1.Cells(r, "c") <> "" Or sh1.Cells(r, "e") <> "" Then
                sh2LastRow = sh2LastRow + 1
                sh1.Rows(r).Copy sh2.Cells(sh2LastRow, "a")
                'here put timestamp on Sheet1
                'sh1.Cells(r, "f") = Format(Now, "mm/dd/yyyy hh:mm:ss")
                'here put timestamp on Sheet2
                sh2.Cells(sh2LastRow, "f") = Format(Now, "mm/dd/yyyy hh:mm:ss")
            End If
        Next
    End Sub
    Regards,
    Antonio
    Last edited by antoka05; 06-08-2008 at 03:51 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