Copy sht1 to sht2 based criteria (Script.Dictionary)

marreco

Well-known Member
Joined
Jan 1, 2011
Messages
609
Office Version
  1. 2010
Platform
  1. Windows
I need copy data to another sheet
My tab("Relatorio") hava CFOP in column M, if find any value start 1 or 2 like this(
1253/AA1949/ZZ2102/AA2353/AA2920/AA)

<tbody>
</tbody>
Copy to tab("Saida") case start like this(
5921/AA6152/AA6202/AA

<colgroup><col width="64" span="3"></colgroup><tbody>
</tbody>
)

Copy to tab("Entrada")


CFOPGo to tab
1253/AAEntrada
1949/ZZEntrada
2102/AAEntrada
2353/AAEntrada
2920/AAEntrada
5921/AASaida
6152/AASaida
6202/AASaida

<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>
</tbody>
This is the code:
Code:
Sub Copy_sht1_To_sht2()
'This code made by  Fluff, I try adapt
    Dim ws As Worksheet
    Dim UsdRws As Long
    Dim Fltr As Variant
    Dim Val As Variant
    Dim Cl As Range
    Dim Dict As Object
    
    Set ws = Sheets("Relatorio")
    UsdRws = ws.Cells(Rows.Count, 1).End(xlUp).Row
    Set Dict = CreateObject("scripting.dictionary")
    Fltr = Array("5*", "6*") 'Array("5921/AA", "6152/AA", "6202/AA")
    
    With ws
        For Each Val In Fltr
            For Each Cl In .Range("M2:M" & UsdRws)
                If Cl.Value Like Val Then Dict(Cl.Value) = vbNullString
            Next Cl
        Next Val
        .Range("A1:AS" & UsdRws).AutoFilter Field:=13, Criteria1:=Dict.Keys, Operator:=xlFilterValues
        .AutoFilter.Range.Offset(1).Copy Sheets("Saida").Range("A" & Rows.Count).End(xlUp).Offset(1)
        'If Cl.Value = Fltr Then
        '    .Range("A1:AS" & UsdRws).AutoFilter Field:=13, Criteria1:=Dict.Keys, Operator:=xlFilterValues
        '    .AutoFilter.Range.Offset(1).Copy Sheets("Saida").Range("A" & Rows.Count).End(xlUp).Offset(1)
        'Else
        '    .Range("A1:AS" & UsdRws).AutoFilter Field:=13, Criteria1:=Dict.Keys, Operator:=xlFilterValues
        '    .AutoFilter.Range.Offset(1).Copy Sheets("Entrada").Range("A" & Rows.Count).End(xlUp).Offset(1)
        'End If
    End With
    ws.AutoFilterMode = False
    Set ws = Nothing
    Set Dict = Nothing
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try
Code:
Sub marreco()
   Dim UsdRws As Long
   
   With Sheets("Relatorio")
      If .AutoFilterMode Then .AutoFilterMode = False
      UsdRws = .Range("M" & Rows.Count).End(xlUp).Row
      .Range("A1:AS" & UsdRws).AutoFilter 13, "5*", xlOr, "6*"
      .AutoFilter.Range.Offset(1).Copy Sheets("Entrada").Range("A" & Rows.Count).End(xlUp).Offset(1)
      .Range("A1:AS" & UsdRws).AutoFilter 13, "1*", xlOr, "2*"
      .AutoFilter.Range.Offset(1).Copy Sheets("Saida").Range("A" & Rows.Count).End(xlUp).Offset(1)
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Yeah, this work!

But I try learn about script.Dictinary. Can you provide a example using dictionary?

Thank you!!
 
Upvote 0
There's no need to use a Dictionary for that.
If you want examples of Dictionaries, just do an advance search and it will pull up loads of threads.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

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