+ Reply to Thread
Results 1 to 10 of 10

Cutting/Pasting Rows based on content PT 2

Hybrid View

Lmsloman Cutting/Pasting Rows based on... 09-19-2006, 03:43 PM
colofnature How's this: Sub... 09-19-2006, 04:11 PM
Lmsloman OOPS. I need it to CUT the... 09-19-2006, 04:31 PM
colofnature No, that's just copying the... 09-19-2006, 04:39 PM
Lmsloman Col, right now, i'm... 09-19-2006, 04:58 PM
colofnature None at all, I'm afraid...... 09-19-2006, 05:16 PM
Lmsloman I'm getting ready to test it... 09-19-2006, 05:44 PM
colofnature Bizarre behaviour 09-21-2006, 06:20 AM
Lmsloman Thank you my new genius... 09-21-2006, 06:33 AM
colofnature Yeah, it copies the row then... 09-21-2006, 06:36 AM
  1. #1
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    None at all, I'm afraid... I tested it out and it worked fine, including the row that didn't move for you. If the reason comes to me I'll let you know, but hopefully one of the good people who hang around on this forum (who are, I must say, an exceptionally bright bunch) might have a clue because right now I'm baffled, sorry.


    C
    If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.

  2. #2
    Registered User
    Join Date
    08-24-2006
    Location
    Maryland
    Posts
    50
    I'm getting ready to test it on another report from another day. Cross your fingers.....

    I need a good scotch after this whole mess!

    thanks buddy!

    -your grateful servant, laura

  3. #3
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301

    Bizarre behaviour

    For some reason, occasionally the For...Next loop was skipping from B2 to B4 without checking B3 - I haven't a clue why, as when I rearranged the rows in random order it didn't do it every time. But changing the Cut to Copy and then clearing the values in the row seems to solve it:

    Sub copy_if_matches_criteria()
    
        Dim wshSource As Worksheet, wshDest As Worksheet
        Dim rngCell As Range
         
        If Intersect([b:b], ActiveSheet.UsedRange) Is Nothing Then Exit Sub
         
        Set wshSource = ActiveSheet
        Set wshDest = Sheets.Add(before:=ActiveSheet)
        wshDest.Name = "TS"
         
        wshSource.Select
        For Each rngCell In Intersect([b:b], Range(Rows(2), Cells.SpecialCells(xlCellTypeLastCell)))
            If (rngCell.Value * 1 >= 300 And rngCell.Value * 1 <= 399) Or _
                (rngCell.Value * 1 >= 1100 And rngCell.Value * 1 <= 1199) Or _
                (rngCell.Value * 1 >= 4018 And rngCell.Value * 1 <= 4025) Or _
                (rngCell.Value * 1 = 4028) Or rngCell.Value * 1 = 4011 Then
                rngCell.EntireRow.Copy wshDest.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
                rngCell.EntireRow.Value = Empty
            End If
        Next
         
        wshSource.[1:1].Copy wshDest.[a1]
        Intersect([b:b], ActiveSheet.UsedRange).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        wshDest.Select
         
    End Sub
    Got there in the end...


    C

  4. #4
    Registered User
    Join Date
    08-24-2006
    Location
    Maryland
    Posts
    50
    Thank you my new genius friend.....only one question.

    I'm not at work yet, so I haven't had a chance to try it out, but you said you changed the cut to copy? because i need it cut

    just curious

  5. #5
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Yeah, it copies the row then clears the cells - same effect as cutting, just an extra step


    C

+ 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