|

楼主 |
发表于 2023-9-26 08:24:54
|
显示全部楼层
感谢回复! 窗体肯定有的,要不怎么91增加到139都正常
Public c As String
Sub test()
Dim i As Integer
Dim str1, str2 As String
str1 = ""
For i = 62 To 81
str2 = "Private Sub Label" & i + 1 & "_Click()" & Chr(10) & _
"UserForm2.Caption = 'A-" & i & "'" & Chr(10) & _
"Me.Label" & i + 1 & ".BackColor = RGB(236, 28, 36)" & Chr(10) & _
"UserForm2.Show" & Chr(10) & _
"End Sub" & Chr(10) & _
"Private Sub Label" & i + 1 & "_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)" & Chr(10) & _
"Me.Label" & i + 1 & ".BackColor = RGB(88, 88, 88)" & _
"End Sub" & Chr(10)
str1 = str1 + str2
Next
Sheet2.Range("a1") = str1
End Sub
Sub CaptionSet()
Dim str As String
Dim i As Integer
For i = 2 To 216
If i <= 7 Then
With UserForm1.Controls("Label" & i)
.Caption = "A1" & i - 8
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 13 Then
With UserForm1.Controls("Label" & i)
.Caption = "A2" & i - 14
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 19 Then
With UserForm1.Controls("Label" & i)
.Caption = "A3" & i - 20
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 25 Then
With UserForm1.Controls("Label" & i)
.Caption = "A4" & i - 26
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 31 Then
With UserForm1.Controls("Label" & i)
.Caption = "A5" & i - 32
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 37 Then
With UserForm1.Controls("Label" & i)
.Caption = "A6" & i - 38
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 43 Then
With UserForm1.Controls("Label" & i)
.Caption = "A7" & i - 44
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 49 Then
With UserForm1.Controls("Label" & i)
.Caption = "A8" & i - 50
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 55 Then
With UserForm1.Controls("Label" & i)
.Caption = "B1" & i - 56
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 61 Then
With UserForm1.Controls("Label" & i)
.Caption = "B2" & i - 62
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 67 Then
With UserForm1.Controls("Label" & i)
.Caption = "B3" & i - 68
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 73 Then
With UserForm1.Controls("Label" & i)
.Caption = "B4" & i - 74
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 79 Then
With UserForm1.Controls("Label" & i)
.Caption = "B5" & i - 80
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 85 Then
With UserForm1.Controls("Label" & i)
.Caption = "B6" & i - 86
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 91 Then
With UserForm1.Controls("Label" & i)
.Caption = "B7" & i - 92
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 97 Then
With UserForm1.Controls("Label" & i)
.Caption = "B8" & i - 98
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 103 Then
With UserForm1.Controls("Label" & i)
.Caption = "B9" & i - 104
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 109 Then
With UserForm1.Controls("Label" & i)
.Caption = "C1" & i - 110
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 115 Then
With UserForm1.Controls("Label" & i)
.Caption = "C2" & i - 116
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 121 Then
With UserForm1.Controls("Label" & i)
.Caption = "C3" & i - 122
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 127 Then
With UserForm1.Controls("Label" & i)
.Caption = "C4" & i - 128
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 133 Then
With UserForm1.Controls("Label" & i)
.Caption = "C5" & i - 134
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 139 Then
With UserForm1.Controls("Label" & i)
.Caption = "C6" & i - 140
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 145 Then
With UserForm1.Controls("Label" & i)
.Caption = "C7" & i - 146
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 151 Then
With UserForm1.Controls("Label" & i)
.Caption = "C8" & i - 152
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 157 Then
With UserForm1.Controls("Label" & i)
.Caption = "C9" & i - 158
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 163 Then
With UserForm1.Controls("Label" & i)
.Caption = "D1" & i - 164
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 169 Then
With UserForm1.Controls("Label" & i)
.Caption = "D2" & i - 170
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 175 Then
With UserForm1.Controls("Label" & i)
.Caption = "D3" & i - 176
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 181 Then
With UserForm1.Controls("Label" & i)
.Caption = "D4" & i - 182
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 187 Then
With UserForm1.Controls("Label" & i)
.Caption = "D5" & i - 188
.TextAlign = fmTextAlignCenter
End With
ElseIf i <= 193 Then
With UserForm1.Controls("Label" & i)
.Caption = "D6" & i - 194
.TextAlign = fmTextAlignCenter
End With
End If
Next
End Sub
Sub queryUserform2()
Dim arr1 As arr
Set arr1 = New arr
Dim i As Integer
i = arr1.ArrEqualTextval(Left(UserForm2.Caption, Len(UserForm2.Caption) - 11), Sheet1)
If i > 0 Then
UserForm2.TextBox1.Text = Sheet1.Range("b" & i).Value
UserForm2.TextBox3.Text = Sheet1.Range("c" & i).Value
Set arr1 = Nothing
Set arr1 = New arr
i = arr1.ArrEqualTextval(UserForm2.TextBox1.Value, Sheet2)
If i > 0 Then
UserForm2.TextBox2.Text = Sheet2.Cells(i, 2).Value
End If
Set arr1 = Nothing
End If
End Sub |
|