使用设置范围进行排序,但在使用一次之后不会更改该值(Using a Set Range to Sort, but it never changes the value after using it once)
我在这里有一个代码用于其基本目标...双击标题将按列D进行排序,然后按列双击进行排序。
是的,我知道这可以通过多重排序更容易地完成,但这不是...的原因选项。
问题是,在代码运行一次之后,它的工作状态很好,它“似乎”永久性地将我的“Set KeyRange”设置为点击值。
如果我手动使用表格并尝试双击一个新标题,它仍会根据首次选择的标题对其进行分类。
我怎样才能解决这个问题? 谢谢。 我试着在结尾附近添加一个新的Set Key范围命令,但是这个命令什么都没做,或者破坏了它。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim KeyRange As Range Dim ColumnCount As Integer ColumnCount = Range("A1:D12").Columns.Count Cancel = False If Target.Row = 1 And Target.Column <= ColumnCount Then Cancel = True Set KeyRange = Range(Target.Address) End If With ActiveSheet.Sort .SortFields.Add Key:=Range("D1"), Order:=xlAscending .SortFields.Add Key:=KeyRange, Order:=xlAscending .SetRange Range("A1:D12") .Header = xlYes .Apply End With End Sub
I have a code here that works for its base goal... Double clicking on a header will sort by Column D, then Sort by the Column Double Clicked.
Yes, I know that this can be more easily accomplished through a Multiple Sort, but thats not an option for...reasons.
The problem, is that after the code has been run once, where it works just fine, it "seems" to be permenantly setting my "Set KeyRange" to the clicked value.
If I manually resort the table, and try to Doubleclick a new header, it still sorts it according to the header selected the first time.
How can I fix this? Thanks. I tried adding a new Set Key range command near the end, but that did nothing, or broke it.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim KeyRange As Range Dim ColumnCount As Integer ColumnCount = Range("A1:D12").Columns.Count Cancel = False If Target.Row = 1 And Target.Column <= ColumnCount Then Cancel = True Set KeyRange = Range(Target.Address) End If With ActiveSheet.Sort .SortFields.Add Key:=Range("D1"), Order:=xlAscending .SortFields.Add Key:=KeyRange, Order:=xlAscending .SetRange Range("A1:D12") .Header = xlYes .Apply End With End Sub
原文:https://stackoverflow.com/questions/48757067
最满意答案
您必须使用隐藏字段,当用户选择一个复选框时,将其添加到隐藏字段,如逗号分隔ID,当每个页面移动时,由于分页检查,如果当前页面中的任何ID属于隐藏字段,如果是标记它们以进行检查。
You have to use the hidden field , when user select a checkbox , add it to hidden field like comma separated Ids , when every page is moved because of pagination check if any of the id in the current page is belong to the hidden field if yes mark them to checked.
相关问答
更多-
jquery mobile 页面跳转第二次不刷新怎么办[2022-09-17]
checkbox -
jquery mobile本地和环境中显示问题[2023-06-25]
checkbox -
jquery mobile 点击跳转不加载数据怎么回事[2023-11-26]
checkbox -
jQuery Mobile框架弹窗中放表单文本框,整个弹窗区域都会变为文本框的触发焦点,不想这样[2022-03-02]
checkbox -
如何在 jQuery Mobile 的 Listview 中动态移除某一条的图标[2023-09-01]
checkbox -
您正在维护两个数组,一个捕获所有已检查的复选框值,即cb,并将这些数据连接到另一个名为cbAdd的数组,此处您正在复制值。 让我们使用单个数组cbAdd如下 - $(document).on("change", ".checkBox", function(){ var value = $(this).val(); var index = cbAdd.indexOf(value); if ($(this).is(":checked")) { cbAdd.push(value ...
-
为了简化,这是你应该做的。 您需要决定如何返回或存储值。 是否使用XML / Registry / CustomXML等等。一旦确定,请执行以下步骤。 功能区XML:
VBA代码: Public Function Function_Clicked(control As IRibbonContro ... -
隐藏的复选框值不包含在jQuery .serialize()中(Hidden checkbox values are not included in jQuery .serialize())[2022-01-16]
解决方案是取消隐藏复选框序列化,并重新隐藏它们。 这不会导致一堆复选框出现和消失,因为它发生得太快了。 The solution was to unhide the checkboxes serialize, and re-hide them. This does not result in a bunch of checkboxes appearing and disappearing because it happens so fast. -
您必须使用隐藏字段,当用户选择一个复选框时,将其添加到隐藏字段,如逗号分隔ID,当每个页面移动时,由于分页检查,如果当前页面中的任何ID属于隐藏字段,如果是标记它们以进行检查。 You have to use the hidden field , when user select a checkbox , add it to hidden field like comma separated Ids , when every page is moved because of pagination check ...
-
jquery复选框插件没有初始化datatables分页(jquery checkbox plugin not initialising on datatables pagination)[2023-02-26]
而不是使用属性选择器,使用类选择器: '.js-switch:not(.switched)' 你拥有的选择器是不可能的。 或者,相反,即使元素具有switched类, :not()部分也总是匹配。 你说,“让我的元素有一个'js-switch'类,其class属性正好'切换'。” 如果class属性完全'切换',它也不能有'js-switch'类。 Instead of using the attribute selector, use the class selector: '.js-switch:no ...