0

我编译了以下代码:

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

此工作表更改的主要功能是从 cell 中读取completein progress从下拉列表中读取S3。我在一列中有一系列下拉列表,它们都需要执行 about 例程,但我很难选择特定列中的整个范围。

4

1 回答 1

1

您可以尝试这样做来选择 entier 列:

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
于 2013-01-16T13:32:47.513 回答