细胞验证和阵列
有两个问题,首先你能提醒我如何在分配多维数组时对其进行填充吗?我总是用 for 循环来完成它,如何静态地完成它似乎让我无法理解?
但我真正想做的是使用数组来验证单元格内容。但是在下面的示例中,我只想使用第二维中的第一个元素。
即
0,0
1,0
2,0
3,0
4,0
有没有办法更新 .Add Type:=xlValidateList, Formula1:=Join(ary, ",") 行,以便它只从 5 x 4 数组返回这 5 个值?
干杯
亚伦
Sub test()
Dim ary As Variant
ReDim ary(5,4)
ary = Array("Value1", "Value2", "Value3", "test", "test2", "test3", "test4")
With ActiveSheet.Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:=Join(ary, ",")
.IgnoreBlank = False
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
two questions, first can you remind me how to polulate a multidimensional array when assigning it? I always do it with for loop and how to staticly do it seems to escape me?
But what I am really looking to do is to use the array to validate cells contents. however in the example below I want to use only the first element in the 2nd dimension.
ie
0,0
1,0
2,0
3,0
4,0
Is there any way to update the .Add Type:=xlValidateList, Formula1:=Join(ary, ",") line so it only returns these 5 values from a 5 by 4 array?
Cheeers
aaron
Sub test()
Dim ary As Variant
ReDim ary(5,4)
ary = Array("Value1", "Value2", "Value3", "test", "test2", "test3", "test4")
With ActiveSheet.Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:=Join(ary, ",")
.IgnoreBlank = False
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 2D 数组大小调整为 1D 很快
下面的代码用示例数据填充 5*4 数组,然后第二个循环仅将第一个维度提取到新的 1D 数组,其行长度与初始数组相同
The resizing of a 2D array to 1D is quick
The code below populates your 5*4 array with sample data, a second loop then extracts only the first dimension to a new 1D array withe the same row length as your initial array