Results 1 to 6 of 6

Thread: If Conditions are met, It wil transfer to another worksheet.

  1. #1
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0

    If Conditions are met, It wil transfer to another worksheet.

    Hello.

    Please help me to seperate the following. All of these are the found in one worksheet.

    On column K if found the word Received and Pending, the whole row will transfer to another sheet named Errors and Others.
    On column Z and AA if found the word Error, the whole row will transfer to another sheet named Errors and Others.

    Please help!

    THanks in advance! :D

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    See 'Similar threads' at the bottom of this page. Post back if that doesn't help.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0
    Hi there, I have a different situations compared to other that has a similar posts.

    Please help me.


    Thanks!

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Untested. Adjust the ranges and sheet names.

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim wksSource       As Worksheet
        Dim wksDest         As Worksheet
        Dim rngFound        As Range
        Dim LastRow         As Long
        Dim x, i            As Long
        
        Const SourceCol1 = 11   'col K
        Const SearchKey1 = "Received,Pending,aron" 'separated by comma
        Const SourceCol2 = 26   'col Z
        Const SourceCol3 = 27   'col AA
        Const SearchKey2 = "Error"
        
        Set wksSource = Worksheets("Sheet1")    'adjust source sheet name
        Set wksDest = Worksheets("Errors and Others")   'adjust destination sheet name
        
        Application.ScreenUpdating = 0
        With wksSource.Columns(SourceCol1)
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            With .Cells(1, 1).Resize(LastRow)
                x = Split(SearchKey1, ",")
                For i = 0 To UBound(x)
                    .AutoFilter 1, x(i)
                    On Error Resume Next
                    Set rngFound = Nothing
                    Set rngFound = .Cells(1).Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(12)
                    On Error GoTo 0
                    If Not rngFound Is Nothing Then
                        rngFound.EntireRow.Copy wksDest.Cells(SourceCol1 & wksDest.Rows.Count).End(xlUp).Offset(2)
                    End If
                    .AutoFilter
                Next
            End With
        End With
        
        With wksSource.Columns(SourceCol2)      'second source
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            With .Cells(1, 1).Resize(LastRow)
                x = Split(SearchKey2, ",")
                For i = 0 To UBound(x)
                    .AutoFilter 1, x(i)
                    On Error Resume Next
                    Set rngFound = Nothing
                    Set rngFound = .Cells(1).Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(12)
                    On Error GoTo 0
                    If Not rngFound Is Nothing Then
                        rngFound.EntireRow.Copy wksDest.Cells(SourceCol1 & wksDest.Rows.Count).End(xlUp).Offset(2)
                    End If
                    .AutoFilter
                Next
            End With
        End With
        
        With wksSource.Columns(SourceCol2)      'third source column
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            With .Cells(1, 1).Resize(LastRow)
                x = Split(SearchKey2, ",")
                For i = 0 To UBound(x)
                    .AutoFilter 1, x(i)
                    On Error Resume Next
                    Set rngFound = Nothing
                    Set rngFound = .Cells(1).Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(12)
                    On Error GoTo 0
                    If Not rngFound Is Nothing Then
                        rngFound.EntireRow.Copy wksDest.Cells(SourceCol1 & wksDest.Rows.Count).End(xlUp).Offset(2)
                    End If
                    .AutoFilter
                Next
            End With
        End With
        Application.ScreenUpdating = 1
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0
    Hi,

    There is nothing happens when I am running the codes. I have completed the necessary requirements to fully run it.

    Please help.

  6. #6
    Senior Member alansidman's Avatar
    Join Date
    Apr 2012
    Posts
    125
    Rep Power
    14
    Are you getting error messages? What do they say? Which line is highlighted?

Similar Threads

  1. Insert Value When A Conditin is Met
    By Ajit in forum Excel Help
    Replies: 3
    Last Post: 09-12-2013, 06:58 PM
  2. How To Move Transfer Or Copy Data To A Protected Sheet
    By rich_cirillo in forum Excel Help
    Replies: 7
    Last Post: 07-13-2013, 06:52 PM
  3. Replies: 4
    Last Post: 07-08-2013, 05:36 PM
  4. Replies: 2
    Last Post: 07-02-2013, 06:52 PM
  5. Print Nth Worksheet To Mth Worksheet using VBA
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-28-2013, 06:57 PM

Posting Permissions

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