VBA loop copy and paste

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Gill

    VBA loop copy and paste

    I need a loop that goes does column B4: B20 and finds a date and copies the data adjacent in C4: c20 until the end date in different cells

    Start date is in F3, and end date in F4: In rows b are months ie: 1/1/2002, 2/1/2002 etc.
    Row C consists of data (300, 200 etc).

    Code:
    dim x as string, dim y as string
    Dim found as boolean
    
    'where the user puts in the start date and the loop will go and find it in rows b
    x=worksheets("sheet2").range (f3") 
    'the end date which the user enters
    y=worksheets("sheet2").range("f4")
    
    'selecting the start of the data
    Range("b5").select
    'running the loop, or at least I am trying too
    
    Do until Isempty(activecell)
       If activecell.value=x then
    found=true
    exit do
    end if
    'selects the bottom cell and keeps going down to search "x"
    activecell.offset(1,0).select
    loop
    If found=true then
    'when the date is found it copies the adjacent cell
    activecell.offset(0,1).copy
    end if

    Where I am having trouble is pasting the cell, and then continuing the loop until the other date is reached which is ("Y")-y=worksheets("s heet2").range(" f4")


    Please let me know if you can help
    Last edited by MMcCarthy; Oct 17 '10, 09:36 PM. Reason: added code tags
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    This will work:
    Run through the data and put the results in an array.
    Dump this array later in the sheet on the right place.
    Do you need help with this ?
    If so, is it possible to attach in Bytes a sheet so we can work on the same data ? (if to big, just ad a part of the data).
    If possible, attach also an example how the final result must look like.

    Comment

    Working...