简体   繁体   English

为什么我的代码没有填写?

[英]Why isn't my code filling down?

Dim SLR As Range
Dim ELR As Range

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next


Select Case UCase(Target.Value)

Case "START-LOCATION"
    Target.Offset(0, 0).Select
    Selection.ClearContents
    SLR = ActiveCell.Address
    Target.Offset(-1, 1).Select



Case "END-LOCATION"
    Target.Offset(0, 0).Select
    Selection.ClearContents
    ELR = ActiveCell.Address
    Target.Offset(0, -1).Select
    ActiveSheet.Range(SLR, ELR).FillDown

End Select
End Sub

Hello all, I have the above code, it is supposed to set the variable on start location for the first cell, and on end location it sets the second variable and then fills down the cells from SLR to ELR, however it isn't working and isn't providing me with an error message, any ideas? 大家好,我有上面的代码,应该在第一个单元格的开始位置设置变量,在结束位置上它设置第二个变量,然后将单元格从SLR填充到ELR,但是它不起作用并没有向我提供错误消息,有什么想法吗?

Try to change the followings: 尝试更改以下内容:

SLR= Activecell.Address 

into 进入

Set SLR = Activecell

and do the same for ELR: 并对ELR执行相同操作:

Set ELR = Activecell

On Error Resume Next is always a bad idea. 关于错误恢复,下一步总是一个坏主意。 If I was king of the world I would make this command illegal, the error handler should be for when something unexpected happens that crashes your code. 如果我是世界之王,那么我将使该命令成为非法,那么错误处理程序应适用于发生意外情况并使您的代码崩溃的情况。

The most import thing with your macro is that the data the user gets at the end of it is correct. 宏最重要的是,用户在其末尾获得的数据是正确的。 If that means that when the code crashes and the user call you over then that's what it takes. 如果那意味着当代码崩溃并且用户致电给您,那么就是这样。 But having On Error Resume Next means that no one will ever know if your code has crashed and no one will ever know that the data is wrong. 但是拥有On Error Resume Next意味着没人会知道您的代码是否崩溃了,也没人会知道数据是错误的。

Never ever use On Error Resume Next!!!!! 永远不要使用On Error Resume Next !!!!!

As for this bit of code you'll learn more about your problem if you remove On Error Resume Next. 至于这段代码,如果您删除On Error Resume Next,您将了解有关您的问题的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM