+ Reply to Thread
Results 1 to 5 of 5

Macros to Copy Certain Rows from One Workbook to Another Workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Macros to Copy Certain Rows from One Workbook to Another Workbook

    Hi, I have similar issue, But I want needs to copy if it contains "Approved" "Rejected" "Hold".

    But below is accepting only "Approved" how to add other 2. If copy non-blanks also ok for me.
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
            With Target
                If .Count > 1 Then Exit Sub
                If Not Intersect(Range("U:U"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, -1).ClearContents
                    Else
                        With .Offset(0, -1)
                            .NumberFormat = "dd mmm yyyy"
                            .Value = Now
                        End With
                    End If
                    Application.EnableEvents = True
                End If
            End With
            If Target.Column <> 21 Then Exit Sub
            If Target.Text <> "Approved" Then Exit Sub
            Application.ScreenUpdating = False
            Dim oSH1 As Worksheet
            Set oSH1 = ThisWorkbook.ActiveSheet
            Dim wbCallLogs As Workbook
            Set wbCallLogs = Workbooks.Open("C:\Rajesh Kanna\Tools\Copy range to different workbook\Data.xls")
            Dim oSH As Worksheet
            Set oSH = wbCallLogs.Worksheets("Calls")
            Dim r As Long
            r = oSH.Cells(oSH.Rows.Count, 21).End(xlUp).Row + 1
            oSH.Range(r & ":" & r).Value = oSH1.Range(Target.Row & ":" & Target.Row).Value
            wbCallLogs.Close (True)
        End Sub
    Last edited by arlu1201; 05-14-2012 at 02:12 PM. Reason: Please put code tags in future.

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Macros to Copy Certain Rows from One Workbook to Another Workbook

    Try this:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
     With Target
     If .Count > 1 Then Exit Sub
     If Not Intersect(Range("U:U"), .Cells) Is Nothing Then
     Application.EnableEvents = False
     If IsEmpty(.Value) Then
     .Offset(0, -1).ClearContents
     Else
     With .Offset(0, -1)
     .NumberFormat = "dd mmm yyyy"
     .Value = Now
     End With
     End If
     Application.EnableEvents = True
     End If
     End With
     If Target.Column <> 21 Then Exit Sub
     If Target.Text = "Approved" Or Target.Text = "Rejected" Or Target.Text = "Hold" Then
        Application.ScreenUpdating = False
        Dim oSH1 As Worksheet
        Set oSH1 = ThisWorkbook.ActiveSheet
        Dim wbCallLogs As Workbook
        Set wbCallLogs = Workbooks.Open("C:\Rajesh Kanna\Tools\Copy range to different workbook\Data.xls")
        Dim oSH As Worksheet
        Set oSH = wbCallLogs.Worksheets("Calls")
        Dim r As Long
        r = oSH.Cells(oSH.Rows.Count, 21).End(xlUp).Row + 1
        oSH.Range(r & ":" & r).Value = oSH1.Range(Target.Row & ":" & Target.Row).Value
        wbCallLogs.Close (True)
     End If
     End Sub
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

  3. #3
    Registered User
    Join Date
    04-30-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Macros to Copy Certain Rows from One Workbook to Another Workbook

    Thanks Kalshaer. Its working great. I am breaking my heads for last 6 hours. I am not good on Excel.

  4. #4
    Registered User
    Join Date
    04-30-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Macros to Copy Certain Rows from One Workbook to Another Workbook

    Hi Kalshaer, Hope you are doing good.

    Need your help once again. In the below once selection done in column "U", it will date and time automatically in column "T" and copy the list of info to another workbook. Until that no problem for me.

    I need to add lock option. Once any choice is selected in "U"and copied I want the cell needs to be lock to avoid further selection in single cell. Based on below, it is not happening. Pls help.

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
     With Target
     If .Count > 1 Then Exit Sub
     If Not Intersect(Range("U:U"), .Cells) Is Nothing Then
     Application.EnableEvents = False
     If IsEmpty(.Value) Then
     .Offset(0, -1).ClearContents
     Else
     With .Offset(0, -1)
             .NumberFormat = "dd mmm yyyy hh:mm:ss"
             .Value = Now
     End With
     End If
     Application.EnableEvents = True
     End If
     End With
     If Target.Column <> 21 Then Exit Sub
     If Target.Text = "Approved" Or Target.Text = "Rejected" Or Target.Text = "Hold" Then
        Application.ScreenUpdating = False
        Dim oSH1 As Worksheet
        Set oSH1 = ThisWorkbook.ActiveSheet
        Dim wbCallLogs As Workbook
        Set wbCallLogs = Workbooks.Open("C:\Rajesh Kanna\Tools\Copy range to different workbook\Data.xls")
        Dim oSH As Worksheet
        Set oSH = wbCallLogs.Worksheets("Calls")
        Dim r As Long
        r = oSH.Cells(oSH.Rows.Count, 21).End(xlUp).Row + 1
        oSH.Range(r & ":" & r).Value = oSH1.Range(Target.Row & ":" & Target.Row).Value
        wbCallLogs.Close (True)
        End If
     
     'Worksheet_Change(ByVal Target As Range)
        If Target.Cells.Count > 1 Then Exit Sub
        If Not Intersect(Target, Range("t1:t10")) Is Nothing Then 'set your range here
            ActiveSheet.Unprotect Password:="123"
            Target.Locked = True
            ActiveSheet.Protect Password:="123"
        End If
    End Sub
    Last edited by Cutter; 09-16-2012 at 07:40 AM. Reason: Added code tags

  5. #5
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macros to Copy Certain Rows from One Workbook to Another Workbook

    @ rajeshapril14

    Welcome to the forum.

    Please notice that code tags have been added to your posts. The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.

+ 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