VBA限制文本长度Excel

时间:2018-02-06 20:51:22

标签: excel vba excel-vba

我对几个小时前的问题有一个跟进问题,但没有得到回复。我在这里。

下面的代码,如何才能使它只适用于列?更具体地,E14:E1000。

select substring(@sql,charindex('Bucket #:',@sql)+len('BUCKET #:')+1,18)

1 个答案:

答案 0 :(得分:1)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim testRange As Range

Set testRange = Range("e14:e1000")

If Not Intersect(Target, testRange) Is Nothing Then
    Application.EnableEvents = False

    For Each cell In Intersect(Target, testRange)
    If Len(cell) > 10 Then
        MsgBox "Text length in cell """ & cell.Address(0, 0) & """ is more than 10.", vbExclamation
        Application.Undo
        Exit For
    End If
    Next cell

Application.EnableEvents = True
End If

End Sub