vba 下拉多选

news/2024/10/21 23:15:57/

方法一:有效性验证下拉多选

  • 建立下拉单选:https://jingyan.baidu.com/article/1876c85255d929890a13767d.html
  • 设置多选代码:
Sub Worksheet_Change(ByVal Target As Range)Dim xRng As RangeDim xValue1 As StringDim xValue2 As String' 为了确保用户在Excel操作时只选中了单个单元格If Target.Count > 1 Then Exit Sub' 当加上On Error Resume Next语句后,如果后面的程序出现"运行时错误"时,会继续运行,不中断。On Error Resume Next' 定位含有验证条件的单元格Set xRng = Cells.SpecialCells(xlCellTypeAllValidation)If xRng Is Nothing Then Exit SubApplication.EnableEvents = False' Intersect函数 返回两个或多个单元格重叠的部分 例子:Intersect(Range('a1:d5'), Range('c4:g9'))If Not Application.Intersect(Target, xRng) Is Nothing ThenxValue2 = Target.Value' 事件响应,假如工作表发生改变,Undo,撤销该表Application.UndoxValue1 = Target.ValueTarget.Value = xValue2If xValue1 <> "" ThenIf xValue2 <> "" Then' InStr函数' 第1个参数1代表从xValue1的第一个位置开始查找;' 第2个参数 要搜索的字符串;' 第3个参数 搜索到的字符串' & 字符串连接符If xValue1 = xValue2 Or InStr(1, xValue1, "," & xValue2) Or InStr(1, xValue1, xValue2 & ",") ThenTarget.Value = xValue1ElseTarget.Value = xValue1 & "," & xValue2End IfEnd IfEnd IfEnd IfApplication.EnableEvents = TrueEnd Sub
注:上面的代码无法反选;
  • 参考1 https://blog.csdn.net/weixin_43564923/article/details/87193978 【亲测可用】(可以反选的代码)
  • 参考2 https://blog.csdn.net/T_amo/article/details/107039058 【亲测可用】

方法二:控件下拉多选

  • 参考1 https://itnoteshare.com/note/404/publicNoteDetail.htm 【亲测可用】

  • 参考2 https://zhuanlan.zhihu.com/p/55353022 【亲测可用】

  • 参考3 http://www.exceloffice.net/archives/3477 【亲测可用】

  • 20210625 下拉添加序号


http://www.ppmy.cn/news/258722.html

相关文章

LINUX挂载硬盘,调整分区大小

https://www.wn789.com/22049.html https://www.wn789.com/3477.html https://blog.csdn.net/jiandanjinxin/article/details/69969217 https://www.osyunwei.com/archives/9368.html 我的Archlinux发现root(/)分区不够用了&#xff0c;于是想把/home分区的空间腾出一些来&…

如何从椭圆度 matlab,如何利用matlab画出如图潮流椭圆

clc;clear %先对分量进行调和分析,然后利用elli_para2程序计算椭圆要素,ap2ep程序画潮流椭圆 %% xlsend = [3477 3897 3477 3478]; lat_point = [39+39.922/60 39+42.356/60 39+37.024/60 39+25.933/60]; tidename = [O1 ;K1 ;M2 ;S2 ;M4 ;MS4 ]; color={r;g;…

log4j:WARN No such property [datePattern] in org.apache.log4j.RollingFileAppender.

log4j:WARN No such property [datePattern] in org.apache.log4j.RollingFileAppender.log4j:ERROR setFile(null,true) call failed.java.io.FileNotFoundException: log/log.txt (系统找不到指定的路径。) at java.io.FileOutputStream.openAppend(Native Method) at java.i…

hdu3774

/* 分析&#xff1a; 水题&#xff0c;不过题目真难读懂 - -I。 len代表绳长、sum代表所有pitch的高度之和、max最高的pitch&#xff0c; 那么&#xff1a; 1、若len<2*sum&#xff0c;则不行&#xff1b; 2、最多的人数(50(60/70)/max)1; */ #include"stdio.…

hdu3747

/* 分析&#xff1a; 读完题立刻就想到了搜索&#xff0c;不过感觉有点不对劲&#xff0c; 因为全选与反选的作用太绝对了&#xff0c;所以貌似可以找规律&#xff0c; 于是&#xff0c;下面的我用的方法就诞生了~ -、-I 仔细想想&#xff1a; (1)全选&#xff1a;要用的话第一…

[BZOJ 3477] [Usaco2014 Mar Gold] Sabotage

金组的神题喵。。 [题目描述] 给你N个数&#xff0c;第一个和最后一个不能去掉。 现希望去掉中间某段连续的数&#xff0c;使得剩下的数的平均值最小化。 之前已经做了很久&#xff0c;一直想不到正解。。然后去网上查&#xff0c;发现没有。。 又去USACO上看官方题解&#…

7744

aabb问题 1.简单的计算 #include<stdio.h> #include<math.h> int main(){int a, b, n;double m;for(a 1; a < 9; a){for(b 0; b < 9; b){n a * 1100 b * 11;m sqrt(n);if(floor(m 0.5) m){printf("%d\n",n);}}}return 0; } 2.枚举 #includ…

hdu3714

/* 分析&#xff1a; 三分。 每个F(x)都是这n个函数、在这一个x点的、最大值&#xff0c; 求F[x]在[0,1000]内的最小值。 2012-10-08 */ #include"stdio.h" #include"string.h" #include"stdlib.h" #include"math.h" #define e 1e-9 i…