Consulting

Results 1 to 6 of 6

Thread: Solved: Copy data from one Worksheet to another based on Flag

  1. #1
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    2
    Location

    Solved: Copy data from one Worksheet to another based on Flag

    Hello everyone,

    I am extremely new and have searched with no solution to my situation. Here goes.

    I have two worksheets within a workbook. They are labeled as test1 and test2.

    test1 contains data that is updated daily by and individual. The data is broken down by column name. (ie, name, address, phone and a date colmn.)

    What I would like to do is at the end of every week take any data that has a date in the date column and copy it from test1 to test2.

    If anyone could possibly help with this I would greatly appreciate it.

    Thank you.

  2. #2
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location
    I would write a macro that identifies what to copy over with a formula.
    So, in your first non-used column (let's assume column Z), put in a formula =if(D1>"12/30/2008","COPY",""). This assumes column D is your date column.

    Then you can do a select special cells on column Z. Select - Special Cells - Non Blank. Copy the entire row and paste into Worksheet("Test2").

  3. #3
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    2
    Location
    Thank you for the reply. Is there a way to automate the whole thing. Such as a macro that will copy from test1 and then paste to test2?

  4. #4
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location
    [vba]
    Sub CopyStuff
    With WS.Range("Z2:Z" & WS.UsedRange.Rows.Count)
    .Formula = "=If(D2>""12/30/2008"",""COPY"","""")
    .Value = .Value
    On Error GoTo Handler
    .SpecialCells(xlCellTypeConstants).EntireRow.Copy Destination:=WS2.Range("A2")
    .ClearContents
    End With
    On Error GoTo 0
    Exit Sub
    End Sub
    [/vba]

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Another way:

    [VBA]
    Option Explicit
    Sub Copy()
    Dim cl As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Test1")
    With ws

    For Each cl In .Range("Z2:Z" & .Range("Z65536").End(xlUp).Row)
    If cl.Value <> "" Then
    cl.EntireRow.Copy Worksheets("Test2").Range("A65536").End(xlUp).Offset(1, 0)
    End If
    Next cl
    End With
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Regular
    Joined
    Jan 2009
    Posts
    93
    Location

    Smile Both methods in one file, good night, Pavel

    Thank you, for this example, Pavel

Posting Permissions

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