Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation Excel数据验证参考电子表格位置与静态列表_Validation_Excel_Vba - Fatal编程技术网

Validation Excel数据验证参考电子表格位置与静态列表

Validation Excel数据验证参考电子表格位置与静态列表,validation,excel,vba,Validation,Excel,Vba,我在一些Excel数据验证方面遇到问题。在一张纸上,我有一个值列表,其中包含填充验证下拉列表的列表,如下所示: A1 |1.) New Item A2 |2.) Miscellaneous A3 |3.) Change Order A4 |4.) Choose the item being broken out: A5 | Caulk NP-1 A6 | Safety signs A7 | Warning lines A8 |

我在一些Excel数据验证方面遇到问题。在一张纸上,我有一个值列表,其中包含填充验证下拉列表的列表,如下所示:

A1 |1.) New Item A2 |2.) Miscellaneous A3 |3.) Change Order A4 |4.) Choose the item being broken out: A5 | Caulk NP-1 A6 | Safety signs A7 | Warning lines A8 | Snow fence A9 | Drain Lead 4 lb 30"x30" A10 | Cant Strip A11 | Screws 1 5/8" A12 | SS Sheet Metal 24 gauge A13 | Sheet Metal Aluminum 040 mill finish A14 | Sheet Metal Aluminum .050 mill finish A15 | Termination Bar A16 | Lead Boots 2" A17 | Lead Boots 3" A18 | Modified Bitumen Smooth APP A19 | TREMCO ELS Mastic A20 | TREMCO Polyroof SF A21 | TREMCO Base sheet fasteners A22 | TREMCO BURmastic Composite A23 | TREMCO PowerPly Standard A24 | TREMCO BURmastic SF A25 | TREMCO PowerPly HD Base Sheet A26 | TREMCO PowerPly Standard FR A27 | TREMCO Burmesh 6" A28 | TREMCO Site visits A29 | TREMCO Reglet Sealant A30 | TREMCO WB Primer A31 | TREMCO Ice Coating A32 | TREMCO Tremflash tape A33 | TREMCO Warranty A34 | 1/4" x 1 1/2" drive pins A35 | SS Roof Nails 1 1/4" A36 | Freight A37 | Auto Fuel A38 | PA Direct Labor Supervisor A39 | PA Direct Labor Sheet Metal A40 | PA Direct Labor Roof Coating A41 | Equipment Crane 45 ton A42 | Equipment Crane 70 ton A43 | Platform Hoist R&G 400 28' A44 | Sqeegies 24" Notched A45 | Dumpsters A46 | Porta John A47 | Permit A48 | Subcontractor RK Hydro Vac A49 | Subcontractor Roofing ICG A50 | Subcontractor Lightning Protection A51 | Misc A52 | Subtotal 1.) New Item,2.) Miscellaneous,3.) Change Order,4.) Choose the item being broken
out:, Caulk NP-1 , Safety signs, Warning lines
非常感谢你的帮助。这真的令人沮丧

使用
vbTab

比如说

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="1,2,3," & vbTab & "          4,5"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With
快照

希望这就是你想要的

跟进

使用上述方法有一个缺点。DVlist不能超过255个字符

备选方案


将列表复制到工作表最左边的一列(XFD列(excel 2007/2010)或IV列(excel 2003)),以便隐藏它,然后在DV中使用它

好的,因此,一开始这是可行的,但在进一步检查后,它不是。虽然Excel仍处于打开状态,但它似乎工作正常。但是,如果我试图保存该文件,然后重新打开Excel,它会说文件中有错误,必须修复。当它修复时,它说它修复了验证,事实上已经删除了它……我无法重现这个问题。即使在我关闭并再次打开该文件后,该文件仍能正常工作。你能分享你正在使用的确切代码吗?好的,我将编辑原始问题,包括代码和填充下拉列表的完整项目列表。代码没有问题;)这是数据。您的数据有引号(“”),因此当您连接字符串时,即使是引号也会被连接起来,这会给您带来错误。让我看看我能不能做点什么:)噢。哇!用两个引号替换所有引号的替换函数怎么样?
    With Range(ActiveCell.Offset(MiscStartRow - ActiveCell.Row + 1, 0), ActiveCell.Offset(TotalRow - ActiveCell.Row + 5, 0)).Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=ValidationList
    .IgnoreBlank = False
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With
With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="1,2,3," & vbTab & "          4,5"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With