+ Reply to Thread
Results 1 to 2 of 2

Thread: Copying the values from a sheet if the values match

  1. #1
    Registered User
    Join Date
    06-10-2011
    Location
    Trondheim
    MS-Off Ver
    Excel 2003
    Posts
    38

    Copying the values from a sheet if the values match

    Hi! I'm not sure if I'm in need of a macro or if this is something that can be done using functions.

    But basically, I want to copy the entire columns A to D from Sheet1 into Sheet2. But only the rows that are NOT the value of 0.

    I've got this function =Sheet1!A1. And then I just copy that into the other cells.
    This has the advantage of automatic updates if the values in Sheet1 are changed.
    But is it possible to edit the function to add an IF or something? Or would I need a macro to do this?

  2. #2
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    PA
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    926

    Re: Copying the values from a sheet if the values match

    Here are a couple ways, Could use more information or example workbook.
    Sub zero()
    Dim cell As Object
    Dim r As Range
    Dim lrow As Long
    Dim ThatRow As Long
    Application.ScreenUpdating = False
    ThatRow = Sheets(2).Range("A65536").End(xlUp).Row + 1
        lrow = Range("A65536").End(xlUp).Row
            Set r = Range("A2:A" & lrow)
                For Each cell In r
                    If cell.Value > 0 Then
    ''''This copies entire row to sheet 2
                        'cell.EntireRow.Copy Destination:=Sheets(2).Range("A" & Thatrow)
               'or
     
    ''''This Copies A:D to sheet 2
                        Range(cell, cell.Offset(, 4)).Copy Destination:=Sheets(2).Range("A" & ThatRow)
                    ThatRow = ThatRow + 1
                    End If
                Next cell
    Application.ScreenUpdating = True
    End Sub
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0