Results 1 to 6 of 6

Thread: Copy rows based on a condition

  1. #1
    Join Date
    Jul 2009
    Posts
    24

    Copy rows based on a condition

    I had created worksheet in Excel file which consists of some data in colums and rows. Now i need to create a code where i can copy entire row into separate worksheet depending on it's data. So i ask my friend about it he told me that this is possible in VBA but don't have much more idea about it. Can anyone help me out with this issue.

  2. #2
    Join Date
    Dec 2008
    Posts
    128

    Copy rows based on a condition

    If you want to create a code where i can copy entire row into separate worksheet depending on it's data then i would suggest you to use the below code and have a check for the same hope it works

    Code:
    Public Sub patxlb()
    
    Dim lng_Dest_Row As Long
    Dim str_Dest_Sht As String
    
    For i = 2 To Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Rowd
        str_Dest_Sht = Sheets("Data").Cells(i, "G").Value
        lng_Dest_Row = Sheets(str_Dest_Sht).Cells(Rows.Count, 1).End(xlUp).Row + 1
        Sheets("Data").Rows(i).Copy Destination:=Sheets(Sheets("Data").Cells(i, "G").Value).Cells(lng_Dest_Row, 1)
    Next i
    
    End Sub

  3. #3
    Join Date
    Jul 2009
    Posts
    24

    Copy rows based on a condition

    Thanks for replying me i had try to use the above code it's not working for me, whenever i am trying to use the code it's giving me some error code which i had forget, does anyone knows any why i am getting error code or can provide me any other code where which will work properly as per my requirements.

  4. #4
    Join Date
    Dec 2008
    Posts
    164

    Copy rows based on a condition

    Hey buddy use this code i am sure you won't face any issue because i had already tested this code and it's workign fine at my place, if you get any error message then it seems that you had made some mistake

    Code:
    Public Sub patxlb()
    
    Dim lng_Dest_Row As Long
    Dim str_Dest_Sht As String
    
    For i = 2 To Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
        str_Dest_Sht = Sheets("Data").Cells(i, "G").Value
        lng_Dest_Row = Sheets(str_Dest_Sht).Cells(Rows.Count, 1).End(xlUp).Row + 1
        Sheets("Data").Rows(i).Copy Destination:=Sheets(Sheets("Data").Cells(i, "G").Value).Cells(lng _Dest_Row, 1)
    Next i
    
    End Sub

  5. #5
    Join Date
    Jul 2009
    Posts
    49

    Copy rows based on a condition

    Hello friends,

    I am also having similar type of issue where i want to copy entire row of data from my worksheet to another worksheet called as EE where Column P contains Terms. I had tried out many code but none of them are workign properly for me, can anyone help me out with it because it's very important for me. Please help

  6. #6
    Join Date
    Apr 2008
    Posts
    193

    How to copy rows based on a condition

    Try to use the below code where i am assuming that sheet one has a heading on first row and data starts from Row 2 and P column doesn't have any empy cells in it and EE sheet will have heading so that the data will start copying from row 2

    Code:
    Set i1 = Sheets("sheet one ") 
    Set e1 = Sheets("EE") 
    Dim d1 
    Dim j1 
    d1 = 1 
    j1 = 2 
    
    Do Until IsEmpty(i1.Range("Q" & j1)) 
    
    If i1.Range("Q" & j1) = "TERM" Then 
    d1 = d1 + 1 
    e1.Rows(d).Value = i1.Rows(j1).Value 
    
    End If 
    j1 = j1 + 1 
    Loop

Similar Threads

  1. Comparing Nokia Symbain based phone vs Windows based
    By Rounder1 in forum Portable Devices
    Replies: 8
    Last Post: 02-11-2011, 05:01 PM
  2. Replies: 4
    Last Post: 01-04-2011, 02:00 AM
  3. How To Copy Rows having Colored Cells by Macro
    By dogaman in forum Windows Software
    Replies: 3
    Last Post: 16-11-2010, 03:23 AM
  4. Replies: 2
    Last Post: 09-07-2009, 08:57 AM
  5. How to copy specific rows to another sheet
    By Jayden in forum Windows Software
    Replies: 1
    Last Post: 21-04-2009, 09:59 PM

Tags for this Thread

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
  •  
Page generated in 1,713,249,076.43177 seconds with 16 queries