+ Reply to Thread
Results 1 to 5 of 5

Copy-Paste range based on condition

Hybrid View

Link Copy-Paste range based on... 06-06-2011, 07:09 AM
MaczaQ Re: Copy-Paste range based on... 06-06-2011, 09:45 AM
MaczaQ Re: Copy-Paste range based on... 06-06-2011, 09:48 AM
Link Re: Copy-Paste range based on... 06-06-2011, 10:07 AM
MaczaQ Re: Copy-Paste range based on... 06-06-2011, 01:10 PM
  1. #1
    Registered User
    Join Date
    02-07-2008
    Posts
    60

    Copy-Paste range based on condition

    Hello all,

    Could you please help me with following request?

    I have attached a workbook as an example. As you can see "Raw data" are included in columns from A to F. I would like to run a macro which will go through all rows and will check all rows based on time in column B. If the particular row is in time period 7:00 - 17:00 (including 7:00 and 17:00) it will copy data from the particular row to section "Working Hours Only". I need to process only data occurred during working hours.

    I will appreciate all the replies.

    Thank you in advance.
    Attached Files Attached Files
    Last edited by Link; 06-07-2011 at 10:21 AM.

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Copy-Paste range based on condition

    some error in time of sending reply
    Last edited by MaczaQ; 06-06-2011 at 09:49 AM.

  3. #3
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Copy-Paste range based on condition

    Please check out following solution:

    Sub filterRows()
    Dim r, w As Long ' index for row of input data and output data
    Dim down, up, current As Date 'variable for time
    
    'init values
    r = 3
    w = 3
    down = "07:00:00"
    up = "17:00:00"
    
    Do Until Cells(r, 1).Value = "" 'check next row till day will be empty
        current = Cells(r, 2).Value
        If current >= down And current <= up Then 'check criteria and copy data if necessary
           Cells(w, 8).Value = Cells(r, 1).Value
           Cells(w, 9).Value = Cells(r, 2).Value
           Cells(w, 10).Value = Cells(r, 3).Value
           Cells(w, 11).Value = Cells(r, 4).Value
           Cells(w, 12).Value = Cells(r, 5).Value
           Cells(w, 13).Value = Cells(r, 6).Value
           w = w + 1
        End If
    r = r + 1
    Loop
    End Sub
    You also shoud change formatting for cells in column H & I

    Best Regards

  4. #4
    Registered User
    Join Date
    02-07-2008
    Posts
    60

    Re: Copy-Paste range based on condition

    Thank you very much. It works exactly as I expected

  5. #5
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Copy-Paste range based on condition

    consider to mark this thread as solved

    Best Regards

+ 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