marreco
Well-known Member
- Joined
- Jan 1, 2011
- Messages
- 609
- Office Version
- 2010
- Platform
- 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(
<tbody>
[TD="width: 64"]1253/AA[/TD]
[TD="width: 64"]1949/ZZ[/TD]
[TD="width: 64"]2102/AA[/TD]
[TD="width: 64"]2353/AA[/TD]
[TD="width: 64"]2920/AA)
[/TD]
</tbody>Copy to tab("Saida") case start like this([TABLE="width: 192"]
<colgroup><col width="64" span="3"></colgroup><tbody>[TR]
[TD="width: 64"]5921/AA[/TD]
[TD="width: 64"]6152/AA[/TD]
[TD="width: 64"]6202/AA[/TD]
[/TR]
</tbody>[/TABLE]
)
Copy to tab("Entrada")
[TABLE="width: 128"]
<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>[TR]
[TD="width: 64"]CFOP[/TD]
[TD="width: 64"]Go to tab[/TD]
[/TR]
[TR]
[TD]1253/AA[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]1949/ZZ[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]2102/AA[/TD]
[TD]Entrada
[/TD]
[/TR]
[TR]
[TD]2353/AA[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]2920/AA[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]5921/AA[/TD]
[TD]Saida[/TD]
[/TR]
[TR]
[TD]6152/AA[/TD]
[TD]Saida[/TD]
[/TR]
[TR]
[TD]6202/AA[/TD]
[TD]Saida[/TD]
[/TR]
</tbody>[/TABLE]
This is the code:
My tab("Relatorio") hava CFOP in column M, if find any value start 1 or 2 like this(
<tbody>
[TD="width: 64"]1253/AA[/TD]
[TD="width: 64"]1949/ZZ[/TD]
[TD="width: 64"]2102/AA[/TD]
[TD="width: 64"]2353/AA[/TD]
[TD="width: 64"]2920/AA)
[/TD]
</tbody>
<colgroup><col width="64" span="3"></colgroup><tbody>[TR]
[TD="width: 64"]5921/AA[/TD]
[TD="width: 64"]6152/AA[/TD]
[TD="width: 64"]6202/AA[/TD]
[/TR]
</tbody>[/TABLE]
)
Copy to tab("Entrada")
[TABLE="width: 128"]
<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>[TR]
[TD="width: 64"]CFOP[/TD]
[TD="width: 64"]Go to tab[/TD]
[/TR]
[TR]
[TD]1253/AA[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]1949/ZZ[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]2102/AA[/TD]
[TD]Entrada
[/TD]
[/TR]
[TR]
[TD]2353/AA[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]2920/AA[/TD]
[TD]Entrada[/TD]
[/TR]
[TR]
[TD]5921/AA[/TD]
[TD]Saida[/TD]
[/TR]
[TR]
[TD]6152/AA[/TD]
[TD]Saida[/TD]
[/TR]
[TR]
[TD]6202/AA[/TD]
[TD]Saida[/TD]
[/TR]
</tbody>[/TABLE]
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