|
怎么间接实现?
Sub sckh(x, d1)
Dim i As Long
Dim j As Long
Dim lng As Long
Dim lng2 As Long
On Error GoTo ren
If x < 0 Then x = 1
lng = ActiveSheet.UsedRange.Rows.count
lng2 = ActiveSheet.UsedRange.Columns.count
ReDim arr(1 To lng, 1 To 1)
rng = Cells(x, 1).Resize(lng, lng2)
For i = 1 To lng
For j = 1 To lng2
If rng(i, j) <> "" And d1.Exists(j & "a") Then
arr(i, 1) = i
Exit For
End If
Next
Next
Cells(x, lng2 + 1).Resize(lng, 1) = arr
For j = 1 To UBound(arr) - 3
If arr(j, 1) = "" Then Exit For
Next j
j = j - 1
Cells(x + j, 1).Resize(lng - j, lng2 + 1).Sort Key1:=Cells(x + j, lng2 + 1), Order1:=xlAscending
z = Cells(Rows.count, lng2 + 1).End(xlUp).Row + 1
Rows(z & ":" & lng + 2).Delete
Columns(lng2 + 1).Delete
Exit Sub
ren: '错了就换最原始的方法删除空行
On Error GoTo ren1
If i > lng Then
j = 0
For i = UBound(arr) To 1 Step -1
If arr(i, 1) = 0 And j = 0 Then j = i
If arr(i, 1) > 0 And j > 0 Then
If j - i = 1 Then
Rows(x + j - 1).Delete
Else
Rows(x + i & ":" & x + j - 1).Delete
End If
j = 0
End If
Next i
If j > 0 Then
If j = 1 Then
Rows(x + j - 1).Delete
Else
Rows(x & ":" & x + j - 1).Delete
End If
End If
If lng2 < Columns.count Then Columns(lng2 + 1).Delete = ""
End If
ren1:
End Sub
是这一段代码吧?
我没调明白,可以帮忙调整一下吗?我是初学者,我的工作中经常要用到求平均值(其中经常有空白单元格),麻烦帮帮忙,多谢了! |
|