【问题标题】:Loop coding in VBAVBA中的循环编码
【发布时间】:2014-06-10 15:01:03
【问题描述】:

假设我只想复制 A 列中的合同编号,该编号在 C 列中有“Y”(C 列是一个标志,它是 Y 或 N)并将编号粘贴到新选项卡中。我该怎么做?

我试图写一些东西,但没有成功。 =(

谢谢!

Sub Test()

Do

Count = 1

 On Error GoTo ErrHandler
 On Error Resume Next
If Range("CheckContract").Offset(Count, 2).Value = "Y" Then
Range("CheckContract").Offset(Count, 0).Copy
Range("PasteRange").Offset(Count, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
End If

Count = Count + 1

Loop While Range("CheckContract").Offset(Count, 0).Value <> ""
Exit Sub

错误处理程序:

MsgBox Prompt:="Please check the inputs", Buttons:=vbExclamation, Title:="Error Msg"
End Sub

【问题讨论】:

  • 能否请您修复您的代码标记和缩进?另外,提供你无法获取的输出和输入。

标签: vba loops copy-paste


【解决方案1】:

这应该可以工作

Sub Macro1()

Dim lrow As Integer
lrow = ActiveSheet.UsedRange.Rows.Count
    ActiveSheet.Range("$A$1:$C$" & lrow).AutoFilter Field:=3, Criteria1:="Y"
    Columns("A:A").SpecialCells(xlCellTypeVisible).Copy
    Sheets.Add After:=ActiveSheet
    ActiveSheet.Paste
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 2012-05-30
    相关资源
    最近更新 更多