Consulting

Results 1 to 7 of 7

Thread: copying row + 1 row above and copying row + 1 row below

  1. #1
    VBAX Regular
    Joined
    Mar 2015
    Posts
    31
    Location

    copying row + 1 row above and copying row + 1 row below

    Hi,
    I have 2 code to deleting row + 1 row above and deleting row + 1 row below
    Sub DeleteRowsandbove ()
     
     On Error Resume Next
     Do
       ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole).Offset(-1, 0).EntireRow.Resize(2).Delete
     Loop Until Err.Number <> 0
    
    End Sub
    
    Sub DeleteRowsabelow ()
     
     On Error Resume Next
     Do
       ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole).Offset(0, 0).EntireRow.Resize(2).Delete
     Loop Until Err.Number <> 0
    
    End Sub
    I have tried to adapt 2 macro to copying row + 1 row above and copying row + 1 row below
    and paste in D1
    Any help would be greatly appreciated. Thanks in advance.
    Last edited by SamT; 06-28-2015 at 07:36 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub CopyAboveAndBelow()
      ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole) _
       .Offset(-1).EntireRow.Resize(3, Range("A1").CurrentRegion.Columns.Count).Copy Range("D1")
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Mar 2015
    Posts
    31
    Location
    Mr sam Thanks for the reply

    I'm not clear enough in my explanation,

    I have 2 request :

    1- in the first code i want to adapt it to :Loop in col "A" - Find the value "mokhtar" - then copying row + 1 row above - paste in D1

    2- in the second i want to adapt it to :Loop in col "A" - Find the value "mokhtar" - then copying row + 1 row below - paste in D1

    Thanks in advance for all your help!!

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    that does both at same time. Why do two steps?
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Regular
    Joined
    Mar 2015
    Posts
    31
    Location
    First of all thank you for your time and effort, but again
    the First request update the below code to copying row + 1 row below then paste data in D1
    Sub DeleteRowsabelow () 
         
        On Error Resume Next 
        Do 
            ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole).Offset(0, 0).EntireRow.Resize(2).Delete 
        Loop Until Err.Number <> 0 
         
    End Sub 


    the second request update the below code to copying row + 1 row above then paste data in E1
    Sub DeleteRowsandbove () 
         
        On Error Resume Next 
        Do 
            ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole).Offset(-1, 0).EntireRow.Resize(2).Delete 
        Loop Until Err.Number <> 0 
         
    End Sub 
    
    
    



    Million Thanks

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub DeleteRowsabelow () 
     
    On Error Resume Next 
    Do 
        ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole).Offset(0, 0).EntireRow.Resize(2).copy Range("D1")
    Loop Until Err.Number <> 0 
     
    End Sub 
    B]Sub DeleteRowsandbove () 
     
    On Error Resume Next 
    Do 
        ActiveSheet.Columns("A").Find("*mokhtar*", , xlValues, xlWhole).Offset(-1, 0).EntireRow.Resize(2).Copy Range("D1")
    Loop Until Err.Number <> 0 
     
    End Sub 
     
     
    [/B]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Regular
    Joined
    Mar 2015
    Posts
    31
    Location
    Mr sam Thank you so much for this post and your time
    I tested the 2 code it doesn't work
    Hope it is clear now

    Many thanks in advance.

Posting Permissions

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