Results 1 to 4 of 4

VBA; Move row based on cell value to another sheet on same number of row.

Threaded View

  1. #1
    Registered User
    Join Date
    01-01-2015
    Location
    united kingdom
    MS-Off Ver
    2003
    Posts
    17

    VBA; Move row based on cell value to another sheet on same number of row.

    I am using this code to move row based on cell value to another sheet. This code is moving the row which contain ok in column A from sheet1 to sheet2. But I need if find ok in row 20 and cloumn A. Then the row will go to 20 nth row to the sheet2. Suppose row 4,7,4,13,42,45,,98,100 contain ok in column A. I need to move that rows to sheet two in same number of row.
    row 4 will go to 4rth row in shhet2.
    row 7 will go to 7nth row in shhet2.
    row 13 will go to 13nth row in shhet2.
    It will continue for the next row.

    Sub MoveCompleted()
    
        Dim h As Variant
        Dim endrow As Integer
        Dim OL As Worksheet, Cmp As Worksheet
    
        Set OL = ActiveWorkbook.Sheets("sheet1")
        Set Cmp = ActiveWorkbook.Sheets("sheet2")
    
        endrow = OL.Range("A" & OL.Rows.Count).End(xlUp).Row
    
        For h = 2 To endrow
            If OL.Cells(h, "A").Value = "ok" Then
               OL.Cells(h, "A").EntireRow.Cut Destination:=Cmp.Range("A" & Cmp.Rows.Count).End(xlUp).Offset(1)
            End If
        Next
    End Sub
    Last edited by Nirupay Robi; 01-13-2015 at 07:51 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 11-03-2014, 04:17 PM
  2. [SOLVED] Move a row to another sheet in the same workbook based on the value of one cell
    By Philpot in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2013, 07:00 AM
  3. [SOLVED] Move entire row from one sheet to another based on cell value.
    By romanm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-29-2013, 06:20 PM
  4. VBA CODE to move rows from one sheet(1) to another sheet(2) based on data in cell
    By fozzieulo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 02:43 PM
  5. Macro to move rows from one sheet to another sheet based on a cell vaule
    By d55272 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-09-2012, 03:33 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