vba - 编译错误 : For Without Next | Moving row to separate worksheet based on string values in column

标签 vba excel

关闭。这个问题需要details or clarity .它目前不接受答案。












想改进这个问题?通过 editing this post 添加详细信息并澄清问题.


4年前关闭。







Improve this question




问题:

  • 编译错误:
    对于没有下一个

  • 客观的:
  • 如果 Sheet1 上 tblData 中的 L 列等于 strPhase 中指定的任何值,则复制整行。然后取出复制的行并将其添加到 Sheet2 上的 tblClosed。然后从工作表 1 中删除原始行。本质上,它是将行移动到工作表 2。

  • 编辑澄清 11/2 下午 4:00
    Sub closedsheet()
    
    Application.ScreenUpdating = False
    
        Dim datasheet As Worksheet 'where is the data copied from
        Dim closedsheet As Worksheet 'where is the data pasted to
        Dim strPhase() As String
        Dim i As Integer
        Dim intPhaseMax As Integer
        Dim lngLstRow As Long
        Dim rngCell As Range
        Dim finalrow As Integer
        Dim lr As Long 'row counter
        Dim Looper As Integer
    
        intPhaseMax = 6
        ReDim strPhase(1 To intPhaseMax)
    
        strPhase(1) = "LOST"
        strPhase(2) = "BAD"
        strPhase(3) = "UNINTERESTED"
        strPhase(4) = "UNRELATED"
        strPhase(5) = "UNDECIDED"
        strPhase(6) = "BUDGET"
    
        'set variables
        Set datasheet = Sheet1
        Set closedsheet = Sheet2
    
    lr = Range("A" & Rows.Count).End(xlUp).Row
    
    For Looper = LBound(strPhase) To UBound(strPhase)
    
        For i = lr To 6 Step -1
        If Not Sheet1.Range("L8:L300" & lngLstRow).Find(strPhase(Looper), lookat:=xlWhole) Is Nothing Then
            Range(Cells(i, 1), Cells(i, 20)).Copy
            Sheet2.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
            Range(Cells(i, 1), Cells(i, 20)).Delete
        End If
    Next
    
    Sheet2.columns.AutoFit
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    Sheet2.Select
    Sheet2.ListObjects.Add(xlSrcRange, Range("A9:U" & lr), , xlYes).Name = 
    "tblClosed"
    
    End Sub
    

    Sheet 1 Pipeline_Input
    Sheet 2 Closed_Sheet

    最佳答案

    该答案解决了您上一条评论中的问题。

    Dim Looper as Integer
    
    For Looper = Lbound(strPhase) to Ubound(strPhase)
    
        If Not Range("L8:L" & lngLstRow).Find(strPhase(Looper),lookat:=xlWhole) Is Nothing Then 
    
            'copy paste code .... 
    
        End If
    
    Next
    

    关于vba - 编译错误 : For Without Next | Moving row to separate worksheet based on string values in column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47080358/

    相关文章:

    VBA遍历列 - 如果在里面

    excel - 跨工作表突出显示重复项跳过第一个实例

    arrays - vba,选择一个动态矩阵

    loops - 退出 Excel 中的嵌套循环

    excel - 在包含数据的列中查找最后一行并在下面粘贴其他数据并重复

    excel - 简化 COUNTIFS 公式

    excel - 调整ActiveCell.FormulaR1C1

    VBA - 在动态创建的文本框上捕获事件

    ms-access - 如何通过 MS-Access VBA 中的 TextBox.OnKeyUp 属性传递 KeyCode

    sql-server - Excel VBA 错误 End with with out with?