Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 存在For循环时,无For错误的Next_Excel_Vba - Fatal编程技术网

Excel 存在For循环时,无For错误的Next

Excel 存在For循环时,无For错误的Next,excel,vba,Excel,Vba,当每个语句都有一个时,我在我的一个For-each循环上收到一个“Next without-For”。错误突出显示了单元格的for循环 ' Find and delete Dim clear As Range For Each clear In ActiveSheet.UsedRange If clear.Value = "TRANS_DATE" Then clear.Cells.Delete Shift:=xlShiftUp Next clear Dim total As R

当每个语句都有一个
时,我在我的一个For-each循环上收到一个“Next without-For”。错误突出显示了
单元格的for循环

'   Find and delete

Dim clear As Range

For Each clear In ActiveSheet.UsedRange
    If clear.Value = "TRANS_DATE" Then clear.Cells.Delete Shift:=xlShiftUp
Next clear

Dim total As Range
For Each total In ActiveSheet.UsedRange
    If total.Value = "Total Amount:" Then total.Cells.Delete Shift:=xlShiftUp
Next total

Dim cell As Range
For Each cell In ActiveSheet.UsedRange
    If cell.Interior.Color = Excel.XlRgbColor.rgbYellow And cell.Font.ColorIndex = RGB(255, 0, 0) Then
    cell.Delete Shift:=xlShiftUp
Next cell

Dim error As Range
For Each error In ActiveSheet.UsedRange
    If error.Interior.Color = Excel.XlRgbColor.rgbYellow Then
    error.EntireRow.Delete Shift:=xlShiftUp

End If
Next
如果您对可能出现的问题提出任何建议,我们将不胜感激

Dim cell As Range
For Each cell In ActiveSheet.UsedRange
    If cell.Interior.Color = Excel.XlRgbColor.rgbYellow And cell.Font.ColorIndex = RGB(255, 0, 0) Then
        cell.Delete Shift:=xlShiftUp
    -------- need and END if here ---------
Next cell
全部代码:

Dim clear As Range

For Each clear In ActiveSheet.UsedRange
    If clear.Value = "TRANS_DATE" Then clear.Cells.Delete Shift:=xlShiftUp
Next clear

Dim total As Range
For Each total In ActiveSheet.UsedRange
    If total.Value = "Total Amount:" Then total.Cells.Delete Shift:=xlShiftUp
Next total

Dim cell As Range
For Each cell In ActiveSheet.UsedRange
    If cell.Interior.Color = Excel.XlRgbColor.rgbYellow And cell.Font.ColorIndex = RGB(255, 0, 0) Then
       cell.Delete Shift:=xlShiftUp
    End If <- added this
Next cell

Dim error As Range
For Each error In ActiveSheet.UsedRange
    If error.Interior.Color = Excel.XlRgbColor.rgbYellow Then
        error.EntireRow.Delete Shift:=xlShiftUp

    End If
Next
Dim clear As Range
对于ActiveSheet.UsedRange中的每个清除
如果clear.Value=“TRANS\u DATE”,则clear.Cells.Delete Shift:=xlShiftUp
下一个明确
变暗总范围
对于ActiveSheet.UsedRange中的每个总计
如果total.Value=“total Amount:,则total.Cells.Delete Shift:=xlShiftUp
下一总数
暗淡单元格作为范围
对于ActiveSheet.UsedRange中的每个单元格
如果cell.Interior.Color=Excel.XlRgbColor.rgbYellow和cell.Font.ColorIndex=RGB(255,0,0),则
cell.Delete Shift:=xlShiftUp

如果您的第三个循环缺少一个
结束,如果
结束,假设它没有如此包装您的代码行。。。那是汉克斯。我似乎遇到了一个问题,VBA在我的“if cell.interior.color=Excel.XlRgbColor.rgbYellow和cell.Font.ColorIndex=RGB(255,0,0)Then…”中检测不到同时满足这两个条件的单元格,并且它跳过了同时具有黄色突出显示和红色字体颜色的单元格。选中以确保颜色是相同的RGB,但仍不会删除它们。。有什么建议吗?如果它没有命中单元格。删除行,那么两个If语句中的一个将是错误的。我会将实际值存储到变量中,然后检查它们是什么。试着找出是黄色还是红色(或两者)不匹配。也许录制新宏,只需将单元格设置为黄色和文本红色,然后比较它在宏代码中生成的值。我认为它不会创建你的RGB(…)位。