Filter it based on one value

satya12

Board Regular
Joined
Oct 19, 2021
Messages
70
Office Version
  1. 2016
Platform
  1. Windows
Hi ,

I am having one company data file, in that file we have to filter one department name and copy that data into another sheet, i tried but its not working with below code, please help
VBA Code:
Sub RMG2()


    Dim PLfilter As String
    
    Set Macro = Workbooks("RMG_Macro.xlsm")
    Set Macrows = Macro.Sheets("Sheet2")
    Set Macrohome = Macro.Sheets("HOME")
    Set RMGSheet = Workbooks("RMG Base report 05 May 2022.xlsx")
    
'    Set RMGSheet = Workbooks.Open(Filename:=(Macrohome.Range("F4").Value))
    Set RMGSheetws = RMGSheet.Sheets("RMG Asso Base Data Report_Deliv")
    Macrows.Rows("2:" & Rows.Count).Delete
    a = RMGSheetws.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To a
    If RMGSheetws.Range("BK" & i).Value = "TAT" Then
        RMG2_1 RMGSheetws:=RMGSheetws, i:=i, Macrows:=Macrows
    End If
        
    Next i



End Sub


Public Sub RMG2_1(ByVal i As Long, ByVal RMGSheetws As Worksheet, ByVal Macrows As Worksheet)

With RMGSheetws
        For Each Condition In .Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible)
            If RMGSheetws.Range("DJ" & i).Value = "Satya" Then
                Macrows.Range("A" & i).Value = Condition.Offset(0, 0).Value
                Macrows.Range("B" & i).Value = Condition.Offset(0, 1).Value
                
                
                Exit For
            ElseIf RMGSheetws.Range("DJ" & i).Value = "Satya 12" Then
                Macrows.Range("A" & i).Value = Condition.Offset(0, 0).Value
                Macrows.Range("B" & i).Value = Condition.Offset(0, 4).Value
                Exit For
            Else
                Exit Sub


            End If
        Next
End With

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top