+ Reply to Thread
Results 1 to 5 of 5

Offset issue?

  1. #1
    BigWave@AC
    Guest

    Offset issue?

    I am looking to paste a row of data onto a cell if the cell meets the
    criteria. What I cannot seem to get this macro to do is move down to
    the next cell, evaluate the contents, if it matches the criteria, paste
    the copied row of data, then move onto the next cell until it
    encounters a blank cell. Any ideas?

    Range("$AP$2:$DZ$2").Select
    Selection.Copy

    Dim rg1 As Range
    Set rg1 = Range("AP12")

    Do Until IsEmpty(rg1)
    If rg1 = "2" Then
    ActiveSheet.Paste
    Else
    Set rg1 = rg1.Offset(1, 0)

    End If
    Loop
    End Sub


  2. #2
    Tom Ogilvy
    Guest

    RE: Offset issue?

    Sub copyData()
    Dim rg1 As Range, cell As Range
    Dim rg2 As Range
    Set rg2 = Range("$AP$2:$DZ$2")
    Set rg1 = Range("AP12", Cells(Rows.Count, "AP").End(xlUp))
    For Each cell In rg1
    If cell.Value = 2 Then
    rg2.Copy cell
    End If
    Next
    End Sub

    --
    Regards,
    Tom Ogilvy

    "BigWave@AC" wrote:

    > I am looking to paste a row of data onto a cell if the cell meets the
    > criteria. What I cannot seem to get this macro to do is move down to
    > the next cell, evaluate the contents, if it matches the criteria, paste
    > the copied row of data, then move onto the next cell until it
    > encounters a blank cell. Any ideas?
    >
    > Range("$AP$2:$DZ$2").Select
    > Selection.Copy
    >
    > Dim rg1 As Range
    > Set rg1 = Range("AP12")
    >
    > Do Until IsEmpty(rg1)
    > If rg1 = "2" Then
    > ActiveSheet.Paste
    > Else
    > Set rg1 = rg1.Offset(1, 0)
    >
    > End If
    > Loop
    > End Sub
    >
    >


  3. #3
    Jim Thomlinson
    Guest

    RE: Offset issue?

    You have all of the pieces but you need to re-arrange them a bit... Try this...

    Dim rg1 As Range
    Set rg1 = Range("AP12")

    Do Until rg1.Value = ""
    If rg1 = "2" Then Range("$AP$2:$DZ$2").Copy Destination:=rng1
    Set rg1 = rg1.Offset(1, 0)
    Loop
    End Sub


    --
    HTH...

    Jim Thomlinson


    "BigWave@AC" wrote:

    > I am looking to paste a row of data onto a cell if the cell meets the
    > criteria. What I cannot seem to get this macro to do is move down to
    > the next cell, evaluate the contents, if it matches the criteria, paste
    > the copied row of data, then move onto the next cell until it
    > encounters a blank cell. Any ideas?
    >
    > Range("$AP$2:$DZ$2").Select
    > Selection.Copy
    >
    > Dim rg1 As Range
    > Set rg1 = Range("AP12")
    >
    > Do Until IsEmpty(rg1)
    > If rg1 = "2" Then
    > ActiveSheet.Paste
    > Else
    > Set rg1 = rg1.Offset(1, 0)
    >
    > End If
    > Loop
    > End Sub
    >
    >


  4. #4
    BigWave@AC
    Guest

    Re: Offset issue?

    Thank you for the tip. works perfectly.


    Jim Thomlinson wrote:
    > You have all of the pieces but you need to re-arrange them a bit... Try this...
    >
    > Dim rg1 As Range
    > Set rg1 = Range("AP12")
    >
    > Do Until rg1.Value = ""
    > If rg1 = "2" Then Range("$AP$2:$DZ$2").Copy Destination:=rng1
    > Set rg1 = rg1.Offset(1, 0)
    > Loop
    > End Sub
    >
    >
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "BigWave@AC" wrote:
    >
    > > I am looking to paste a row of data onto a cell if the cell meets the
    > > criteria. What I cannot seem to get this macro to do is move down to
    > > the next cell, evaluate the contents, if it matches the criteria, paste
    > > the copied row of data, then move onto the next cell until it
    > > encounters a blank cell. Any ideas?
    > >
    > > Range("$AP$2:$DZ$2").Select
    > > Selection.Copy
    > >
    > > Dim rg1 As Range
    > > Set rg1 = Range("AP12")
    > >
    > > Do Until IsEmpty(rg1)
    > > If rg1 = "2" Then
    > > ActiveSheet.Paste
    > > Else
    > > Set rg1 = rg1.Offset(1, 0)
    > >
    > > End If
    > > Loop
    > > End Sub
    > >
    > >



  5. #5
    BigWave@AC
    Guest

    Re: Offset issue?

    Thank you for the tip. works perfectly.


    Jim Thomlinson wrote:
    > You have all of the pieces but you need to re-arrange them a bit... Try this...
    >
    > Dim rg1 As Range
    > Set rg1 = Range("AP12")
    >
    > Do Until rg1.Value = ""
    > If rg1 = "2" Then Range("$AP$2:$DZ$2").Copy Destination:=rng1
    > Set rg1 = rg1.Offset(1, 0)
    > Loop
    > End Sub
    >
    >
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "BigWave@AC" wrote:
    >
    > > I am looking to paste a row of data onto a cell if the cell meets the
    > > criteria. What I cannot seem to get this macro to do is move down to
    > > the next cell, evaluate the contents, if it matches the criteria, paste
    > > the copied row of data, then move onto the next cell until it
    > > encounters a blank cell. Any ideas?
    > >
    > > Range("$AP$2:$DZ$2").Select
    > > Selection.Copy
    > >
    > > Dim rg1 As Range
    > > Set rg1 = Range("AP12")
    > >
    > > Do Until IsEmpty(rg1)
    > > If rg1 = "2" Then
    > > ActiveSheet.Paste
    > > Else
    > > Set rg1 = rg1.Offset(1, 0)
    > >
    > > End If
    > > Loop
    > > End Sub
    > >
    > >



+ 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