计算行数并根据条件导出

时间:2018-11-14 08:00:48

标签: excel vba excel-formula excel-2010

所以我有一个Excel文件,我想将某些行导出到另一个Excel文件中,我的问题是我有这样的行:

1    
1    
1    
2    
2    
2    
3    
3    
3    
1   
1    
1

我想从编号为1的第一行导出到编号为3的最后一行,并在导出后删除相同的行。

到目前为止,我有这个。

Private Sub export2()
folha = exportform.Label14.Caption
On Error GoTo ErrHandler
Application.ScreenUpdating = False


Dim src As Workbook

' ABRIR EXCEL
Set src = Workbooks.Open("U:\Mecânica\Produção\OEE\OEE ( FULL LOG )\FRS\FRS_DADOS.xlsx", True, False)
WS_Count = src.Worksheets.Count
 For o = 1 To WS_Count
 src.Worksheets(o).Unprotect password:="registoOEE"
 Next o

lastsrc = src.Worksheets("DADOS").Range("A65536").End(xlUp).Row
last = Application.ThisWorkbook.Worksheets(folha).Range("A65536").End(xlUp).Row




Dim last, I As Integer
Dim turno As String

Sheets(folha).Select

For I = 2 To last
'If application.ThisWorkbook.Worksheets(folha).Cells(last, 61)














Next I




ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True







  For o = 1 To WS_Count
 src.Worksheets(o).Protect password:="registoOEE"
 Next o


  Application.DisplayAlerts = False 'IT WORKS TO DISABLE ALERT PROMPT

  'SAVES FILE USING THE VARIABLE BOOKNAME AS FILENAME
 src.Save

 Application.DisplayAlerts = True 'RESETS DISPLAY ALERTS

' CLOSE THE SOURCE FILE.
src.Close True             ' FALSE - DON'T SAVE THE SOURCE FILE.
Set src = Nothing


fim:
End Sub

我已经进行了编辑,因此您可以看到我已经拥有的代码,希望对您有所帮助。

1 个答案:

答案 0 :(得分:0)

回答这个10个月的问题,因为它可能会帮助仍在搜索类似结果的人。

我在AI列中对公式进行了计数,以计算AH中值出现的次数,如果AI值大于1,则将其粘贴到不同的工作表中。

代码如下:

    Sub CopyDups()
       With Application
         .ScreenUpdating = False
         .EnableEvents = False
       End With

    Dim cnt As Range
    Dim nu As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet

    Set Source = ActiveWorkbook.Worksheets("SourceData")
    Set Target = ActiveWorkbook.Worksheets("Criteria 1")

    nu = 1     
    For Each cnt In Source.Range("AI1:AI1000")   
      If cnt > 1 Then
        Source.Rows(cnt.Row).Copy Target.Rows(nu)
        nu = nu + 1
      End If
    Next cnt
       With Application
         .ScreenUpdating = True
         .EnableEvents = True
       End With
    End Sub