Consulting

Results 1 to 3 of 3

Thread: Solved: if match column A and B move the row to another sheet

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Question Solved: if match column A and B move the row to another sheet

    I want to use this VBA code but it is not complete currently this VBA check the column A and B matched and afte that move the matched row to another sheet . please help me .

    PHP Code:
    Sub FindAndMove()
         
        
    Dim i As Long
        Dim dCol 
    As Long
        Dim lrow 
    As Long
         
         
    'Column to check first (A)
        dCol = 1
         
         '
    Get last row of dataCol A
        lrow 
    Cells(65536dCol).End(xlUp).Row
         
         
    'Check each row: lastrow to row 2
        For i = lrow To 2 Step -1
             
             '
    If Col A AND Col B are match
            
    If Cells(i1) = Cells(11) And Cells(i2) = Cells(12Then
                 
                
               
            End 
    If
        
    Next i
    End Sub 

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Don't duplicate your posts!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    i'm not sure if below is you're after...

    [VBA]
    Sub FindAndMove()
    'http://www.vbaexpress.com/forum/showthread.php?t=41320

    Dim wsFrom As Worksheet, wsTo As Worksheet
    Dim rngFrom As Range, rngTo As Range
    Dim i As Long, lRow As Long, lCol As Long, calc As Long

    With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
    .EnableEvents = False
    calc = .Calculation
    .Calculation = xlCalculationManual
    End With

    Set wsFrom = Worksheets("Sheet1") 'change Sheet1 to your actual worksheet name with data to move from
    Set wsTo = Worksheets("Sheet2") 'change Sheet2 to your actual worksheet name to move to

    lRow = wsFrom.Cells(Rows.Count, 1).End(xlUp).Row
    lCol = wsFrom.Cells(1, Columns.Count).End(xlToLeft).Column

    wsTo.Cells.Clear
    wsTo.Cells(1, 1).Resize(1, lCol).Value = wsFrom.Cells(1, 1).Resize(1, lCol).Value 'copy header row

    For i = lRow To 2 Step -1
    With wsFrom
    If .Cells(i, 1) = .Cells(i - 1, 1) And .Cells(i, 2) = .Cells(i - 1, 2) Then
    Set rngFrom = .Range(.Cells(i, 1), .Cells(i, lCol))
    With wsTo
    Set rngTo = .Range("A1").Offset(Application.CountA(.Range("A:A")))
    rngTo.Resize(1, lCol).Value = rngFrom.Value
    End With
    .Rows(i).EntireRow.Delete
    End If
    End With
    Set rngFrom = Nothing
    Set rngTo = Nothing
    Next i

    With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
    .EnableEvents = True
    .Calculation = calc
    End With

    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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