如何实现以下目标?
Sub Macro1()
'
' Macro1 Macro
'
'
Worksheets("Drop-down").Select
n = Cells(1, 1).End(xlDown).Row
For i = 1 To n
ActiveSheet.Cells(i, 2).Select
*******************************************************
If Worksheets("Misc").Cells(2, i).Value = "" Then
continue i
End If
*******************************************************
If Worksheets("Misc").Cells(3, i).Value <> "" Then
Set validationRange = Range(Worksheets("Misc").Cells(2, i), Worksheets("Misc").Cells(2, i).End(xlDown))
Else
Set validationRange = Worksheets("Misc").Cells(2, i)
End If
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=validationRange.Address
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Next i
End Sub发布于 2010-05-11 14:42:54
这不是一个简单的流程控制案例吗?我不明白为什么需要特殊的关键字来解决这个问题:
For i = 0 To 10
If Not condition Then
some other code
Next 编辑:或,在您的代码中:
Sub Macro1()
'
' Macro1 Macro
'
'
Worksheets("Drop-down").Select
n = Cells(1, 1).End(xlDown).Row
For i = 1 To n
ActiveSheet.Cells(i, 2).Select
*******************************************************
If Not Worksheets("Misc").Cells(2, i).Value = "" Then
*******************************************************
If Worksheets("Misc").Cells(3, i).Value <> "" Then
Set validationRange = Range(Worksheets("Misc").Cells(2, i), Worksheets("Misc").Cells(2, i).End(xlDown))
Else
Set validationRange = Worksheets("Misc").Cells(2, i)
End If
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=validationRange.Address
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
********
End If
********
Next
End Sub发布于 2010-05-11 14:20:06
回答问题的另一半:
For n = 1 To something
If condition Then
Exit For
End If
' more code
Next n发布于 2010-05-11 14:17:51
vb的关键字不是大写的吗?
For n = 1 To something
If condition Then
Continue For
End If
' more code
Next nContinue关键字可以执行您想要的操作。
http://msdn.microsoft.com/en-us/library/801hyx6f(VS.80).aspx
https://stackoverflow.com/questions/2808424
复制相似问题