|
代码如下。。。
Sub test()
Application.ScreenUpdating = False
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("含空格下拉")
Set sh = wb.Sheets("名称")
arr = sht.Range(sht.[a1], sht.Cells(30, "o"))
For i = 5 To UBound(arr)
If arr(i, 4) = Empty Then '只在此处修改了条件
With sht
With .Cells(i, 5).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Join(Application.Rept(sh.[g1:i1], 1), ",")
.IgnoreBlank = True
.InCellDropdown = True
End With
With .Cells(i, 7).Validation
.Delete
sht.Cells(i, 5) = sh.[g1]
' s = "=INDIRECT(e" & i & ")"
s = "=indirect(indirect(""rc[-2]"",0))"
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=s
' .IgnoreBlank = True
.InCellDropdown = True
sht.Cells(i, 5).ClearContents
End With
.Cells(i, 4).NumberFormat = "General"
.Cells(i, 4) = "=IF(indirect(""rc[3]"",0)="""","""",INDEX(名称!D:D,MATCH(indirect(""rc[3]"",0),名称!E:E,)))"
End With
End If
Next
Beep
Application.ScreenUpdating = True
End Sub
|
|