这好像是一段VB代码吧。新手小白求个翻译。没看太懂。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 2 Then
Dim a, s As String
s = "2009-5-20,2009-5-21,2009-5-22,2009-5-23,2009-5-24"
a = Split(s, ",")
Columns(256).ClearContents
Range("iv1").Resize(UBound(a) + 1) = WorksheetFunction.Transpose(a) '请把有效性所用日期写在iv列上端
ActiveWorkbook.Names.Add Name:="名称1", RefersToR1C1:="=Sheet1!R1C256:R" & Range("IV65536").End(xlUp).Row & "C256"
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=名称1"
End With
Target.NumberFormatLocal = "yyyy-m-d"
End If
End Sub
[解决办法]
EXCEL VBA工作表事件
[code=VB][/code]
Private Sub Worksheet_SelectionChange(ByVal Target As Range) '当工作表选区发生改变时执行本程序(固定格式)
If Target.Column = 2 Then '如果 Target的列标=2 则执行
Dim a, s As String '定义变量 a,s 为 字符串
s = "2009-5-20,2009-5-21,2009-5-22,2009-5-23,2009-5-24" 's="2009-5-20,2009-5-21,2009-5-22,2009-5-23,2009-5-24"
a = Split(s, ",") ' a=<分割字符串>(s,",")
Columns(256).ClearContents '<列>坐标(256 )的清除内容
Range("iv1").Resize(UBound(a) + 1) = WorksheetFunction.Transpose(a) '请把有效性所用日期写在iv列上端 '<单元格>区域("iv1" )的<重调大小>(<数组上限>(a)+1)= 工作表公式的<区域转置>(a)'请把有效性所用日期写在iv列上端
ActiveWorkbook.Names.Add Name:="名称1", RefersToR1C1:="=Sheet1!R1C256:R" & Range("IV65536").End(xlUp).Row & "C256" ' 活动工作簿的名称的添加 名称="名称1",RefersToR1C1="=Sheet1!R1C256:R" & <单元格>区域("IV65536" )的<末端>(方向向上 )的行标 & "C256"
With Target.Validation '工作于 Target的Validation
.Delete '<With对象>的删除
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=名称1" '<With对象>的添加 类型=xlValidateList,警告类型=xlValidAlertStop,Operator=xlBetween,公式1="=名称1"
End With 'With语句结束
Target.NumberFormatLocal = "yyyy-m-d" ' Target的NumberFormatLocal="yyyy-m-d"
End If 'If判断过程结束
End Sub '子程序结束