我编译了以下代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("S3")) Is Nothing Then
Select Case Range("S3")
Case "Complete": Sample
Case "In Progress": InProgress
End Select
End If
End Sub
此工作表更改的主要功能是从单元格complete
的下拉列表中读取in progress
或S3
。我在列中有一系列下拉列表,它们都需要执行约定例程,但是我很难在特定列中选择整个范围。
答案 0 :(得分:1)
您可以尝试此选择整个列:
Sheets(1).Range("S:S")
然后是完整的代码:
'-- you can find last used row of your column and used that as well
'-- Dim LastRow as Long
'-- LastRow = Range("S3").Rows.Count
'-- If Not Intersect(Target, Range("S3").Resize(LastRow)) Is Nothing Then
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("S:S")) Is Nothing Then
'-- change to proper letter case as if the case don't match then case fails..
Select Case StrConv(Target.Value, vbProperCase)
Case "Complete": Sample
Case "In Progress": InProgress '-- not sure if you need to remove the space
End Select
End If
End Sub