PrivateSub Worksheet_SelectionChange(ByVal Target As Range)
With Range("d7").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70"
EndWith
End Sub
如代码:
Formula1 里面的值有70个,我用VBA导出后,直接下拉一条也不显示了
但是我换成
PrivateSub Worksheet_SelectionChange(ByVal Target As Range)
With Range("d7").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19"
EndWith
End Sub
则可以支持下拉!请问这里是否能手动设置下下拉长度呢?求高手赐教!!!不胜感激!
能不能通过引用其它表的数据来显示下拉列表呢,在excel里是可以,不知道程序能不能设置。。
恩!已经实现了!思路其实跟你的思路是差不多的!此问题相信困扰过很多人,所以在这里给大家分享一下!代码是其次,主要是思路问题!
1、首先我在导出EXCEL的时候把用一列将数据源存储,然后隐藏起来!
If _dt.Rows.Count > 0 Then
For m = 0 To _dt.Rows.Count - 1
'在第39行插入业务单元的参数用于下拉菜单的引用
If _dt.Rows(m)(0).ToString() <> "" Then
cell = ws.Cells(m, 39)
cell.Value = _dt.Rows(m)(0).ToString()
cell.Style.Font.Size = 10 * 20
End If
Next
ws.Columns(39).Hidden = True
End If
2、在用VBA做下拉的时候直接引用"=$AN$1:$AN$55“就OK了
xlsRange = xlsSheet.Range(GetColPosition(i))
xlsRange.Validation.Delete()
xlsRange.Validation.Add(Microsoft.Office.Interop.Excel.XlDVType.xlValidateList, Microsoft.Office.Interop.Excel.XlDVAlertStyle.xlValidAlertStop, Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlGreater, "=$AN$1:$AN$55")