我利用Userform做計算時需要選定要計算的欄位
故設定每一個section的起始欄位-"Start Row"及"End Row"
且在Critera存在時才可輸入起始欄位,當它為"N/A"時起使欄位則不可輸入
[attach]15761[/attach]
於是就寫了一長串的code
想問大家同樣的問題會怎麼寫可以比較簡化?
謝謝
'------------------------------------------
If TextBox3.Locked = True Then
CC = 1
Else
If TextBox5.Locked = True Then
CC = 2
Else
If TextBox7.Locked = True Then
CC = 3
Else
If TextBox9.Locked = True Then
CC = 4
Else
If TextBox11.Locked = True Then
CC = 5
End If
End If
End If
End If
End If
iC = 1
Do Until iC > CC
If iC = 1 Then
StartRow = Val(TextBox1.Text)
EndRow = Val(TextBox2.Text)
End If
If iC = 2 Then
StartRow = Val(TextBox3.Text)
EndRow = Val(TextBox4.Text)
End If
If iC = 3 Then
StartRow = Val(TextBox5.Text)
EndRow = Val(TextBox6.Text)
End If
If iC = 4 Then
StartRow = Val(TextBox7.Text)
EndRow = Val(TextBox8.Text)
End If
If iC = 5 Then
StartRow = Val(TextBox9.Text)
EndRow = Val(TextBox10.Text)
End If
If iC = 6 Then
StartRow = Val(TextBox11.Text)
EndRow = Val(TextBox12.Text)
End If
中間計算程式
iC = iC + 1
Loop
'----------------------------------作者: acdx 時間: 2013-8-12 17:37
回復 1#acdx
上面沒講清楚
我在Sub ComboBox1_Change裡有設定當ComboBox1.Value 不等於"N/A"(即C1~C5)時 TextBox才可輸入否則會被Locked
Private Sub ComboBox1_Change()
If ComboBox1.Value = "N/A" Then
TextBox1.Locked = True
TextBox2.Locked = True
TextBox1.BackColor = &H8000000A
TextBox2.BackColor = &H8000000A
Else
TextBox1.Locked = False
TextBox2.Locked = False
TextBox1.BackColor = &H8000000B
TextBox2.BackColor = &H8000000B
End If
End Sub作者: stillfish00 時間: 2013-8-12 20:18
Dim myControl(1 To 6, 1 To 3) As Control
'設定控制項陣列
For i = 1 To UBound(myControl)
Set myControl(i, 1) = Controls("ComboBox" & i)
Set myControl(i, 2) = Controls("TextBox" & 2 * i - 1)