2017-07-26 80 views
-2

我想知道如何执行我的代码以清除从第8列开始0.00的所有内容,并且只要完成写入的列跳到下一行,所以从现在起我要感谢评论和帮助。VBA帮助清除0,00 VBA列的代码

昏暗的RNG作为范围 昏暗林,山坳作为整数

lin = 2 
col = 10 

Cells(lin, col).Select 

Do While ActiveCell.Value <> "" 
    Do While ActiveCell.Value <> "" 
     If ActiveCell.Value = ",00" Then 
      ActiveCell.Value = "" 
     End If 
     col = col + 1 
     Cells(lin, col).Select 
    Loop 
    lin = lin + 1 
    col = 10 
    Cells(lin, col).Select 

Loop 
+7

不要标记垃圾邮件。 – shmosel

+2

这与Java有什么关系?为什么将问题标记为Java问题?了解使用不相关的问题标签可能会引起人们对您的问题的关注,但它可能是*否定的*注意,您不需要关注。 –

+0

对不起,我会删除邮件,我不想将它放入java标记中 –

回答

1

这里是我会做,而不是。我会首先找到最后一列,并用数据找到行号。我将从第8列循环到最后一列,然后对于每一列,我将循环每一行以找到包含0,00的单元格值。

Option Explicit 

'loop from col 8 then go through each line and remove those with 0,00 

Sub RemoveZeros() 

    Dim colNo As Long 
    Dim rowNo As Long 
    Dim lastColNo As Long 
    Dim lastRowNo As Long 
    Dim ws As Worksheet 

    'Assuming your sheet name is Sheet1 
    Set ws = ThisWorkbook.Sheets("Sheet1") 

    With ws 

     'Find the last column and row no with data 
     lastColNo = .Cells(1, .Columns.Count).End(xlToLeft).Column 
     lastRowNo = .Cells(.Rows.Count, 1).End(xlUp).Row 

     'loop through each col and row to find those with value 0,00 
     For colNo = 8 To lastColNo 
      For rowNo = 1 To lastRowNo 
       If .Cells(rowNo, colNo).Value = "0,00" Then 
        .Cells(rowNo, colNo).Value = "" 
       End If 
      Next rowNo 
     Next colNo 

    End With 

End Sub