Results 1 to 16 of 16

Move Entire Row To Different Worksheet Based On Exact Cell Value

Threaded View

  1. #1
    Registered User
    Join Date
    06-03-2014
    Posts
    9

    Move Entire Row To Different Worksheet Based On Exact Cell Value

    Hi there

    I apologise if this has been solved but I have searched and can't find the answer. I have 'stitched' bits of code together and feel so close to solving this. I have this working but it won't 'loop' and therefore only completes the task for individual rows.

    In a nutshell I search Sheet 1, Column Q, Row 3 onwards for a set value and then move the entire row to Sheet 3, Row 3 onwards. My code works but I have to run it 10 times if there are 10 rows that contain the value of 1 in them.

    As you can probably tell, I'm useless at VBA!

    Here is my code....

    Sub MoveRows()
    
    Dim cell As Range
    Dim lastrow As Long, i As Long
    
    lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    
    i = 3
    
    For Each cell In Sheets(1).Range("Q3:Q" & lastrow)
    
        If cell.Value = 1 Then
            cell.EntireRow.Copy Sheets(4).Range("A" & Rows.Count).End(xlUp).Offset(1)
            cell.EntireRow.Delete
            i = i + 1
        End If
            
    Next
    
    End Sub

    If I want to search for a value of 2 and move to sheet 5 then I have to change theses value and keep running again.

    I would like to add this to my code but don't know how to?

    For Each cell In Sheets(1).Range("Q3:Q" & lastrow)
    If cell.Value = 2 Then
            cell.EntireRow.Copy Sheets(5).Range("A" & Rows.Count).End(xlUp).Offset(1)
            cell.EntireRow.Delete
            i = i + 1
        End If
    I can add a sample sheet if required but basically I'm just trying to look at everything in column Q from row 3 onwards so wasn't sure if it was needed as the rest of the row data is irrelevant.

    Thanks for reading this.
    Steve
    Last edited by st3v3y; 06-03-2014 at 06:07 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Move entire row to new worksheet based on specific value
    By D0lph1n in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2014, 11:29 PM
  2. Move entire row to another worksheet based on cell value
    By bdf0827 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-09-2014, 07:01 AM
  3. [SOLVED] Move entire row to another worksheet based on cell value
    By jesseg005 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-03-2013, 12:52 PM
  4. [SOLVED] move entire row to another worksheet based on cell value
    By Berndene in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-14-2012, 10:13 AM
  5. [SOLVED] Move entire row to another worksheet based on cell value
    By mmctague in forum Excel General
    Replies: 11
    Last Post: 06-26-2012, 12:43 PM

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