如果使用VBA前4列为空,则将0放入下一个excel列
大家好,我正在尝试制作一个vb宏,确定一行中是否有4个空单元格,如果有,它应该在下一行中放入0,否则为1。这是我到目前为止所做的如果使用VBA前4列为空,则将0放入下一个excel列,excel,vba,Excel,Vba,大家好,我正在尝试制作一个vb宏,确定一行中是否有4个空单元格,如果有,它应该在下一行中放入0,否则为1。这是我到目前为止所做的 Sub QuickCull() On Error Resume Next Columns("a").SpecialCells(xlBlanks).EntireRow.Delete Columns("b").SpecialCells(xlBlanks).EntireRow.Delete Columns("d").SpecialCells(
Sub QuickCull()
On Error Resume Next
Columns("a").SpecialCells(xlBlanks).EntireRow.Delete
Columns("b").SpecialCells(xlBlanks).EntireRow.Delete
Columns("d").SpecialCells(xlBlanks).EntireRow.Delete
Dim col As Range
Set col = Cells(Rows.Count, "E").End(xlUp)
Dim r As Range
Set r = Range("E2", col).Resize(, 4)
r.Select
Dim cell As Range
For Each cell In r
If cell.Value = "" Then
cell.Value = 0
Else
cell.Value = 1
End If
Next cell
End Sub
通过这种方式,我将一个空白行放入0 instad,我曾想过用这些行的总和生成另一个单元格,但这是一种更为古怪和高效的方法吗?我认为您需要以下内容,显然,用工作表的名称替换“WORKSHEETNAME”:
Dim r as Range, cell as Range, eRow as Long
eRow = Sheets("WORKSHEETNAME").Cells(Rows.Count, 5).End(xlUp).Row
Set r = Sheets("WORKSHEETNAME").Range("E2:E" & eRow)
For each cell in r.cells
If cell.Offset(0,-4).Value = "" _
And cell.Offset(0,-3).Value = "" _
And cell.Offset(0,-2).Value = "" _
And cell.Offset(0,-1).Value = "" Then
cell.Value = 0
Else
cell.Value = 1
End if
Next cell
请添加“之前”和“之后”工作表截图。你的代码有什么问题(如果是的话)