[英]Excel VBA - Sub not finishing after Call with Target
I'm trying to make an a Worksheet that adapts depending on the different selections on the page. 我正在尝试制作一个可根据页面上的不同选择进行调整的工作表。 There are 3 cells wills drop down lists that will modify the page depending on the selected value.
有3个单元格的Wills下拉列表,这些列表将根据所选值来修改页面。 When I launch the sub directly in the Worksheet_SelectionChange it works without problems (as it's only one) but as I needed 3 I wanted to launch it depending on which cell you select.
当我直接在Worksheet_SelectionChange中启动子程序时,它可以正常工作(因为只有一个),但是由于需要3,我想根据您选择的单元格来启动它。 The problem I have now is that the selection works (test done with Showmsg) but everything that should happen after doesn't.
我现在遇到的问题是选择有效(使用Showmsg完成测试),但之后应发生的一切都不起作用。
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D25")) Is Nothing Then
Call LineBlock_Change(Target)
End If
End If
End Sub
---------
Sub LineBlock_Change(ByVal Target As Range) 'D25
Select Case Target
Case "Non Protected / Non Redundant"
' Affichage 1 Ligne
Columns("J:O").Hidden = True
Case Else
' Affichage 2 Ligne
Columns("J:O").Hidden = False
End Select
End Sub
The thing is that when I use the same code of the Sub in Worksheet_SelectionChange(with a limitation on the Cell that can be selected) It does work but while trying to lunch with a Sub it doesn't. 事实是,当我在Worksheet_SelectionChange中使用Sub的相同代码时(对可以选择的单元格有限制),它可以工作,但是在尝试与Sub一起吃午餐时却没有。 I personnaly don't know if it can be followed up like that or if I need to rethink the way of doing it.
我个人不知道是否可以采取这样的后续行动,或者我是否需要重新考虑这样做的方式。
Thanks in advance for any help. 在此先感谢您的帮助。
Update : As I noticed that I might have some problems really explain what I can't do I will try an other approach. 更新:正如我注意到的那样,我可能会遇到一些问题,这些问题确实可以解释我不能做的事情,我将尝试其他方法。 I have this code :
我有这个代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Address <> "$D$25" Then Exit Sub
Select Case Target
Case "Non Protected / Non Redundant"
' Affichage 1 Ligne
Columns("J:O").Hidden = True
Case Else
' Affichage 2 Ligne
Columns("J:O").Hidden = False
End Select
End Sub
It does exactly what I desire, when D25 has the string : "Non Protected / Non Redundant" it hides the Columns J:O. 它完全符合我的要求,当D25具有字符串:“非保护/非冗余”时,它将隐藏列J:O。 Now my problem is that D25 is not the only condition that I wish to have that will hide/unhide columns/rows.
现在我的问题是D25不是我希望拥有的唯一条件,它将隐藏/取消隐藏列/行。 And such I'm trying to write a code that would launch a sub depending on which Cell is selected and what is inside of it.
这样,我正在尝试编写一个代码,该代码将根据选定的单元格及其内部内容启动一个子程序。 Though when I try to write the code in a way that it would work as a sub it doesn't reacts the way I would like (hiding the columns).
尽管当我尝试以一种可以作为子代码的方式编写代码时,它并没有按照我想要的方式做出反应(隐藏列)。
Sub LineBlock_Change(ByVal Target As Range) 'D25
Stop '<- see what happens
Select Case Target
Case "Non Protected / Non Redundant"
' Affichage 1 Ligne
Columns("J:O").Hidden = True
Case Else
' Affichage 2 Ligne
Columns("J:O").Hidden = False
End Select
End Sub
The problem in LineBlock
are the following: LineBlock
中的问题如下:
Column
should be Columns()
Column
应为Columns()
Columns("J:O").EntireRow.Hidden = True
hides the whole worksheeet. Columns("J:O").EntireRow.Hidden = True
隐藏整个工作表。 That's great! EntireRow
part. EntireRow
部分。 Edit: 编辑:
Upon the update, reading that "D25 is not the only condition that I wish to have that will hide/unhide columns/rows" this is what you should do: 更新后,请阅读“ D25不是我希望拥有的唯一条件,它将隐藏/取消隐藏列/行”,这是您应该做的:
Select Case True
Case Target = "Non Protected / Non Redundant"
'some action
Case Range("A1") = "something else"
'some other action
Case Else
Columns("J:O").Hidden = False
End Select
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.