[英]Error 5 in text field change
I'm updating and populating a combobox named textoControles
after updating another combobox named textoCausas
. 在更新另一个名为
textoCausas
组合框之后,我将更新并填充一个名为textoControles
组合框。 The first combobox textoControles
upadtes itself with its change. 第一个组合框
textoControles
对其更改进行了升级。
Now, I'm getting error '5' in this scenario: 现在,在这种情况下,我得到错误“ 5”:
If I have the table ActiveSheet.Name
with no data (empty) and enter data into combobox textoCausas
, and then enter a character (just entering any character) on textoCausas
, then the error '5' stops the macro. 如果我的表
ActiveSheet.Name
没有数据(空),然后将数据输入到组合框textoCausas
,然后在textoCausas
上输入一个字符(只需输入任何字符),那么错误“ 5”将停止宏。
But, if the table ActiveSheet.Name
has any data in the first column and I enter data into textoCausas
no error stops the macro. 但是,如果表
ActiveSheet.Name
的第一列中有任何数据,并且我将数据输入到textoCausas
没有错误会停止宏。
I need some help to solve this error. 我需要一些帮助来解决此错误。 Thanks!
谢谢!
Private Sub textoCausas_AfterUpdate()
Dim ws As Worksheet, controles As Range, planes As Range, utlimafila As Double, numeroCausa As Double, C As Range
Set ws = Worksheets(ActiveSheet.Name)
ultimafila = ws.ListObjects(ActiveSheet.Name).Range.Columns(11).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If ultimafila <> 8 Then
With Me.textoControles
.Clear
If Not IsError(Application.Match(Me.textoCausas.Value, ws.ListObjects(ActiveSheet.Name).ListColumns(1).DataBodyRange, 0)) Then
Set C = ws.ListObjects(ActiveSheet.Name).ListColumns(1).DataBodyRange.Find(textoCausas.Value, LookIn:=xlValues, lookat:=xlWhole)
index = C.Row
numeroCausa = ws.Cells(index, 11)
For Each controles In ws.ListObjects(ActiveSheet.Name).ListColumns(2).DataBodyRange
If controles.Columns(10) = numeroCausa Then
If controles.Value <> Empty Then
.AddItem controles.Value
.List(.ListCount - 1, 1) = controles.Offset(0, 1).Value
End If
End If
Next controles
End If
End With
With Me.textoPlanes
.Clear
If Not IsError(Application.Match(Me.textoCausas.Value, ws.ListObjects(ActiveSheet.Name).ListColumns(1).DataBodyRange, 0)) Then
Set C = ws.ListObjects(ActiveSheet.Name).ListColumns(1).DataBodyRange.Find(textoCausas.Value, LookIn:=xlValues, lookat:=xlWhole)
index = C.Row
numeroCausa = ws.Cells(index, 11)
For Each planes In ws.ListObjects(ActiveSheet.Name).ListColumns(6).DataBodyRange
If planes.Columns(6) = numeroCausa Then
If planes.Value <> Empty Then
.AddItem planes.Value
.List(.ListCount - 1, 1) = planes.Offset(0, 1).Value
End If
End If
Next planes
End If
End With
End If
Me.textoControles = Null
Me.textoPlanes = Null
End Sub
Private Sub textoControles_Change()
Dim ws As Worksheet, C As Range, C2 As Range
Set ws = Worksheets(ActiveSheet.Name)
Me.textoEfectividad = Null
Me.textoFrecuencia = Null
Me.textoResponsable = Null
If Trim(Me.textoControles.Value & vbNullString) = vbNullString Then
Me.textoEfectividad = Null
Me.textoFrecuencia = Null
Me.textoResponsable = Null
Exit Sub
End If
If Not IsError(Application.Match(Me.textoControles.Value, ws.ListObjects(ActiveSheet.Name).ListColumns(2).DataBodyRange, 0)) Then
Set C = ws.ListObjects(ActiveSheet.Name).ListColumns(2).DataBodyRange.Find(textoControles.Value, LookIn:=xlValues, lookat:=xlWhole)
index = C.Row
Set C2 = ws.ListObjects(ActiveSheet.Name).ListColumns(11).DataBodyRange.Find(ws.Cells(index, 11), LookIn:=xlFormulas, lookat:=xlWhole, SearchDirection:=xlPrevious) 'xlFormulas para buscar en celdas ocultas
index2 = C2.Row
For i = index To index2
If ws.Cells(i, 2) = Me.textoControles Then
Me.textoEfectividad = ws.Cells(i, 3)
Me.textoFrecuencia = ws.Cells(i, 4)
Me.textoResponsable = ws.Cells(i, 5)
Exit For
End If
Next i
End If
End Sub
It's the IsError function. 这是IsError函数。 In VBA it tells if a variant has the value vbError.
在VBA中,它告知变量是否具有值vbError。 I wanted to say this yesterday but I couldn't replicate the error.
我想昨天说这个,但我无法复制该错误。 It doesn't seem to result from the Match function.
它似乎不是由Match函数产生的。 Perhaps, the
ListObject
doesn't exist on a blank sheet causing an error to occur which doesn't assign a value of vbError to the variant resulting from the test. 也许
ListObject
在空白表上不存在,导致发生错误,该错误未将vbError的值分配给测试产生的变量。 So, the thing to do is to assign Application.Match(Me.textoControles.Value, ws.ListObjects(ActiveSheet.Name).ListColumns(2).DataBodyRange
to a temporary variable. Precede the line with On Error Resume Next
and follow it with If Err Then
, and your problem should go away. 因此,要做的是将
Application.Match(Me.textoControles.Value, ws.ListObjects(ActiveSheet.Name).ListColumns(2).DataBodyRange
给一个临时变量。在On Error Resume Next
和If Err Then
,则可以解决该问题,而您的问题应该会消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.