|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
试试:
Dim arr, d As Object
Private Sub Workbook_Open()
Dim cnn As Object
Dim SQL As String, i&
Set cnn = CreateObject("adodb.connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no';Data Source=" & ThisWorkbook.Path & "\装配产能.xls" '请自己修改路径
SQL = "Select * from [Sheet1$a2:f65536] where f2 is not null"
arr = cnn.Execute(SQL).GetRows
cnn.Close
Set cnn = Nothing
Set d = CreateObject("scripting.dictionary")
For i = 0 To UBound(arr, 2)
d(arr(1, i)) = i
Next
With Sheet1
.[iv:iv] = ""
.[iv1].Resize(d.Count) = WorksheetFunction.Transpose(d.Keys)
With .[b2:b65536].Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=" & Sheet1.[iv1].Resize(d.Count).Address
End With
End With
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name <> "Sheet1" Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Intersect(Target, [b2:b65536]) Is Nothing Then Exit Sub
If Target = "" Then Exit Sub
If d Is Nothing Then Workbook_Open
Target.Offset(, -1) = arr(0, d(Target.Value))
Target.Offset(, 2) = arr(3, d(Target.Value))
Target.Offset(, 3) = arr(5, d(Target.Value))
End Sub
不同文件夹不同工作薄数据有效性问题.rar
(21.26 KB, 下载次数: 197)
|
|