我看过许多关于循环遍历UserForm控件的帖子,但似乎无法根据我的需要调整我找到的代码,需要帮助。
我正试图找出这样的情景:
下面是我一直在处理的代码,我要么在无限循环中结束,要么我得到
错误424
Private Sub UserForm_Activate()
Dim wb As Workbook
Dim wsRR As Worksheet
Dim bColor As Range
Dim c As Control
Dim y As String
Set wb = Application.ThisWorkbook
Set wsRR = wb.Sheets("RiskRating")
Set bColor = wsRR.Range("C3")
For Each c In JHKey.Controls
If TypeName(c) = "TextBox" Then
y = Left(c, 2)
End If
If y = "ch" Then
c.BackColor = bColor.Interior.Color
End If
Next c
End Sub发布于 2018-08-08 16:05:33
尝试将If语句测试"ch“放在If语句测试"TextBox”中。此外,在检查控件名称时,应指定控件的name属性,否则该属性默认为其Value属性。另外,顺便提一下,我建议用关键字Me代替JHKey,它指的是用户名本身,而不管它的名称如何。
Private Sub UserForm_Activate()
Dim wb As Workbook
Dim wsRR As Worksheet
Dim bColor As Range
Dim c As Control
Dim y As String
Set wb = Application.ThisWorkbook
Set wsRR = wb.Sheets("RiskRating")
Set bColor = wsRR.Range("C3")
For Each c In Me.Controls
If TypeName(c) = "TextBox" Then
y = Left(c.Name, 2)
If y = "ch" Then
c.BackColor = bColor.Interior.Color
End If
End If
Next c
End Subhttps://stackoverflow.com/questions/51750281
复制相似问题