Consulting

Results 1 to 4 of 4

Thread: Solved: Find, Cut, Move & Copy issue

  1. #1

    Solved: Find, Cut, Move & Copy issue

    Hi guys

    Hope you're all doing well. Once more I'm here to lay a minor annoying problem out and hope you can with what is most likely another silly bit of programming from me!

    This little snippet of code is supposed to find the word yes in column G, cut the row and then paste it sequentially on another sheet.

    It fails on the pasting part and I really can't figure out why.

    NB - this works if you put copy where it says cut, but I really do need to cut and paste.

    [vba]' DatamoveR Macro
    '
    Dim r As Long, lastrow As Long, rOut As Long
    rOut = 1
    lastrow = Sheets("Sheet1").range("G65536").End(xlUp).Row
    For r = 1 To lastrow
    If Sheets("sheet1").Cells(r, 7) Like "yes" Then
    Sheets("sheet1").Rows(r).EntireRow.Cut
    Sheets("sheet2").Rows(rOut).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    rOut = rOut + 1
    End If
    Next r

    Application.CutCopyMode = False

    End Sub[/vba]

    Thoughts gentlemen?

    Thanks

    Phel x

  2. #2
    I've actually found a way to get it to work to my advantage while just copying.

    However, if anyone does know why the above won't cut and paste it would be good to know.

    Thanks

    Phel x

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim r As Long, lastrow As Long, rOut As Long

    Sheets("sheet2").Select
    With Sheets("Sheet1")

    rOut = 1
    lastrow = .Range("G65536").End(xlUp).Row
    For r = 1 To lastrow

    If .Cells(r, 7) Like "yes" Then

    .Rows(r).Cut
    Rows(rOut).Select
    ActiveSheet.Paste
    .Rows(rOut).Value = .Rows(rOut).Value
    rOut = rOut + 1
    End If
    Next r
    End With


    Application.CutCopyMode = False
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Star, as always

    x

Posting Permissions

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