Consulting

Results 1 to 6 of 6

Thread: Solved: Posting rows to another sheet some copy, other move

  1. #1

    Solved: Posting rows to another sheet some copy, other move

    Hi all,

    I have a workbook contains three sheets "Data, Demo and Relc"
    Based on values in some field I want a VBA code to move some of the subject row and copy the remaining part of it to the other sheet.

    Please open the attached file for details.

    Thankful for your help and support.
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    Mar 2009
    Posts
    29
    Location

    Copy Relo or Demo

    Hi Khaledocom,

    If I understand you correctly, if you type the word "Relc" the entire row must be copied to the sheet Relc and if you type "Deo" it must be copied to the Demo sheet.

    Paste the following code in the sheet code window.

    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    '/ Poster's name: Khaledocom
    '/ Date: 02/28/2012
    '/ Link: http://www.vbaexpress.com/forum/showthread.php?t=41150
    '/ Source sheet
    Dim wksDt As Worksheet
    Set wksDt = Sheets("Data")
    '/ A receiving sheet
    Dim wksDo As Worksheet
    Set wksDo = Sheets("Demo")
    '/ A receiving sheet
    Dim wksRc As Worksheet
    Set wksRc = Sheets("Relc")

    '/ Determing the last row in column R 'Column 18
    Dim lngRow As Long
    lngRow = wksDt.Cells(Rows.Count, 18).End(xlUp).Row

    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub

    If Not Intersect(Target, Range("R4:R" & lngRow)) Is Nothing Then
    If UCase(Target.Cells.Value) = "DEO" Then
    wksDt.Range(Cells(Target.Cells.Row, 1), Cells(Target.Cells.Row, 18)).Copy
    wksDo.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
    ElseIf UCase(Target.Cells.Value) = "RELC" Then
    wksDt.Range(Cells(Target.Cells.Row, 1), Cells(Target.Cells.Row, 18)).Copy
    wksRc.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
    End If
    End If

    End Sub[/VBA]

    I've also attached a file with the code.

    Regards,
    Xrull
    Attached Files Attached Files

  3. #3
    Thanks a lot Xrull
    But I need it to clear the range("F:R") after posting its values to other sheets.

  4. #4
    VBAX Regular
    Joined
    Mar 2009
    Posts
    29
    Location
    Khaledocom:

    Replace the code in the Data sheet's VBE with this one.
    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    '/ Poster's name: Khaledocom
    '/ Date: 02/28/2012
    '/ Link: http://www.vbaexpress.com/forum/showthread.php?t=41150
    '/ Source sheet
    Dim wksDt As Worksheet
    Set wksDt = Sheets("Data")
    '/ A receiving sheet
    Dim wksDo As Worksheet
    Set wksDo = Sheets("Demo")
    '/ A receiving sheet
    Dim wksRc As Worksheet
    Set wksRc = Sheets("Relc")

    '/ Determing the last row in column R 'Column 18
    Dim lngRow As Long
    lngRow = wksDt.Cells(Rows.Count, 18).End(xlUp).Row

    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub

    If Not Intersect(Target, Range("R4:R" & lngRow)) Is Nothing Then
    If UCase(Target.Cells.Value) = "DEO" Then
    wksDt.Range(Cells(Target.Cells.Row, 1), Cells(Target.Cells.Row, 18)).Copy
    wksDo.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
    wksDt.Range(Cells(Target.Cells.Row, 6), Cells(Target.Cells.Row, 18)).ClearContents
    ElseIf UCase(Target.Cells.Value) = "RELC" Then
    wksDt.Range(Cells(Target.Cells.Row, 1), Cells(Target.Cells.Row, 18)).Copy
    wksRc.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
    wksDt.Range(Cells(Target.Cells.Row, 6), Cells(Target.Cells.Row, 18)).ClearContents
    End If
    End If

    End Sub[/VBA]

    Whenever you are posting a question, please specify all the tasks that a macro is required to do. It will save you a lot of time.

    Regards,
    Xrull

  5. #5
    Thanx a lot, It's really gr8.

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For the benefit of non-english speakers, please don't use text speak.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •