Function hindi(Range As Range) As Integer
Dim Str As Range
Dim Currow As Long
Dim Temp As Integer
Currow = "1"
For Each Str In Range
If Len(Str.Value) = "0" Then
Temp = Range("E" & "Currow-1").Value
End If
Currow = Currow + "1"
Next
hindi = Temp
End Function
在EXCEL的VBA中,我想让EXCEL返回空白单元格上面的那个值,结果总是出现错误,我编写的程序有什么问题?
答案:4 悬赏:50 手机版
解决时间 2021-03-13 20:19
- 提问者网友:斑駁影
- 2021-03-13 11:31
最佳答案
- 五星知识达人网友:天凉才是好个秋
- 2021-03-13 11:57
你这个函数根本不成立. 因为函数都要在单元格里输入, 当你输入函数后,单元格不再是空白. 而且,你定义hindi这个函数是integer型,那如果是其他类型的数据怎么办呢? 反正有问题.
下面是我编写的一个宏, 应该和你的要求差不多.
Sub AutoFill()
Dim i As Long, k As Long
If Selection.Count > 1 Then End
k = ActiveCell.Column
For i = ActiveCell.Row To Cells(65535, k).End(xlUp).Row
If Cells(i, k) = "" Then
Cells(i, k) = Cells(i - 1, k)
End If
Next
End Sub
下面是我编写的一个宏, 应该和你的要求差不多.
Sub AutoFill()
Dim i As Long, k As Long
If Selection.Count > 1 Then End
k = ActiveCell.Column
For i = ActiveCell.Row To Cells(65535, k).End(xlUp).Row
If Cells(i, k) = "" Then
Cells(i, k) = Cells(i - 1, k)
End If
Next
End Sub
全部回答
- 1楼网友:鸽屿
- 2021-03-13 15:48
假设你要查找的空白单元格在b列
sub my()
dim i as long
for i = 1 to [a65536].end(xlup).row
if cells(i, 2) = "" then '这里的2就是你的列数,可以自己替换
rows(i & ":" & i).delete shift:=xlup
end if
next
end sub
- 2楼网友:污到你湿
- 2021-03-13 14:18
在Temp = Range("E" & "Currow-1").Value语句的下面追加语句Exit for退出for循环。代码如下:
Function hindi(Range As Range) As Integer
Dim Str As Range
Dim Currow As Long
Dim Temp As Integer
Currow = "1"
For Each Str In Range
If Len(Str.Value) = "0" Then
Temp = Range("E" & "Currow-1").Value
Exit for
End If
Currow = Currow + "1"
Next
hindi = Temp
End Function
- 3楼网友:持酒劝斜阳
- 2021-03-13 12:51
是不是这样:
Function hindi(Rng As Range) As Integer
Dim Str As Range
Dim Temp As Integer
For Each Str In Rng
If Str = "" Then
Temp = Cells(Str.Row - 1, "E")
End If
Next
hindi = Temp
End Function
你上面代码要这样写:(数字的不要带引号!)
Function hindi(Rng As Range) As Integer
Dim Str As Range
Dim Currow As Long
Dim Temp As Integer
Currow = 1
For Each Str In Rng
If Len(Str.Value) = "0" Then
Temp = Range("E" & Currow - 1).Value
End If
Currow = Currow + 1
Next
hindi = Temp
End Function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯