Results 1 to 8 of 8

Thread: VBA code for moving rows from/to multiple sheets if meets condition

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Seeker samdk's Avatar
    Join Date
    Dec 2018
    Location
    Paris
    Posts
    6
    Articles
    0
    Excel Version
    2013

    Question VBA code for moving rows from/to multiple sheets if meets condition

    I'm quite new to the VBA coding and I like it, so I would love to learn more.
    For serveral days I have been trying to figure out how to solve my problem. Unfortunately, the found answers could only respond to part of it, but never succeed in really adapting them.
    I have 5 databases in different sheets (A, B, C, D and E). The only common information is the column H in each one. And also this value is a unique one.
    On the first sheet I would like to move the entire row from one of these sheets if the value from B2 is found in column H. And after maybe changing some information to be able to move it back on the same sheet, but at the end of the list.

    Click image for larger version. 

Name:	VBA moving rows.jpg 
Views:	23 
Size:	75.9 KB 
ID:	8720


    This is what I was able to do so far (it is only copying the row - but I would like to move it - also I can't get it to search the B2 value in another sheet if is not found in sheet A):

    Code:
    Sub CopyRows()
    Dim c As Range
    Dim x AsInteger
    FindString= Sheets("Feuil1").Range("B2").Value
    CodeF= Sheets("A").Range("H"& Rows.Count).End(xlUp).Row: x =8
    ForEach c In Sheets("A").Range("H1:H"& CodeF)
        If c.Value = Sheets("Feuil1").Range("B2")Then
    c.EntireRow.Copy Worksheets("Feuil1").Range("A"& x)
    x= x +1
        EndIf
    Next c
    End Sub
    
    Hope my description is clear and that something like that can be done with the VBA coding.
    Many thanks in advance for your time!
    Kind regards.
    Sam

    PS: VLookup formula won't work, as I might change some values apart the column H in that specific row.
    Last edited by AliGW; 2018-12-14 at 01:09 PM. Reason: Code tags added.

Tags for this Thread

Posting Permissions

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