[attach]4964[/attach]請教高手
程式如下因MultiPage語法不懂
如何使Page1,2,3執行時不互相干擾有錯請指正
執行到If MultiPage2.Value = True Then時會中斷出現錯誤訊息!
[attach]4961[/attach]
Private Sub CommandButton1_Click()
Dim gj As Variant
Dim kj As Long
ActiveSheet.Unprotect
If MultiPage1.Value = True Then
MsgBox 1
gj = TextBox1
If gj > 35 Or gj < 1 Then Unload Me: MsgBox "欄位超出範圍": Exit Sub
If TextBox3 > 0 Then
'未完成
' Cells(gj + 7, 2) = Range("d3")
' Cells(gj + 7, 4) = "=$d$3"
End If
End If
'*********減資*******************
If MultiPage2.Value = True Then
MsgBox 2
'未完成
If TextBox2 >= 100 Then Unload Me: MsgBox "比例大於100": Exit Sub
kj = Cells(gj + 7, 8)
If kj = 0 Then Unload Me: MsgBox "第" & gj & "筆無資料": Exit Sub
If TextBox2 > 0 Then
Cells(gj + 7, 8) = Int(kj * (1 - (TextBox2 / 100)))
Cells(gj + 7, 10) = Round((Cells(gj + 7, 15) - Cells(gj + 7, 22)) / Cells(gj + 7, 8), 2)
End If
End If
'**PAEG3***********
If MultiPage3.Value = True Then
MsgBox 3
If CheckBox1 = True Then
For gj = 1 To 35
If Cells(gj + 7, 15) = "" Then
MsgBox gj
If gi > 35 Then Exit Sub
Else
If OptionButton1 = True Then
If OptionButton2 = True Then
h = Cells(gj + 7, 21)
Cells(gj + 7, 11) = Cells(gj + 7, 11) - TextBox5
c = Cells(gj + 7, 21)
Cells(gj + 7, 15) = Cells(gj + 7, 15) + TextBox5 + h - c
End If
End If
Next
If gi > 35 Then Exit Sub
End If 'CheckBox1
End If
Q1程式如下因MultiPage語法不懂,如何使Page1,2,3執行時不互相干擾有錯請指正
執行到If MultiPage2.Value = True Then時會中斷出現錯誤訊息!
A1 僅以此問題回答唷 (因為不知道你整個程式是要做什麼用)
在你的表單中僅有一個MultiPage1的物件
當然在執行到If MultiPage2.Value = True Then時會產生錯誤
樓主你要的應該是在切換page時按下確定時執行該page的計算
因此,建議改為select case的寫法 就可以解決了
其它,等樓主有問題時,再提問
如下,程式碼
Private Sub CommandButton1_Click()
Dim gj As Variant
Dim kj As Long
ActiveSheet.Unprotect
Select Case MultiPage1.Value <--MultiPage1.Value:指在MultiPage中的頁碼,起始值為0
Case 0 '<--page1
' If MultiPage1.Value = True Then
MsgBox 1
gj = TextBox1
If gj > 35 Or gj < 1 Then Unload Me: MsgBox "欄位超出範圍": Exit Sub
If TextBox3 > 0 Then
'未完成
' Cells(gj + 7, 2) = Range("d3")
' Cells(gj + 7, 4) = "=$d$3"
End If
' End If
'*********減資*******************
Case 1'<--page2
' If MultiPage2.Value = True Then
MsgBox 2
'未完成
If TextBox2 >= 100 Then Unload Me: MsgBox "比例大於100": Exit Sub
kj = Cells(gj + 7, 8)
If kj = 0 Then Unload Me: MsgBox "第" & gj & "筆無資料": Exit Sub
If TextBox2 > 0 Then
Cells(gj + 7, 8) = Int(kj * (1 - (TextBox2 / 100)))
Cells(gj + 7, 10) = Round((Cells(gj + 7, 15) - Cells(gj + 7, 22)) / Cells(gj + 7, 8), 2)
End If
' End If
'**PAEG3***********
Case 2'<--page3
'If MultiPage3.Value = True Then
MsgBox 3
If CheckBox1 = True Then
For gj = 1 To 35
If Cells(gj + 7, 15) = "" Then
MsgBox gj
If gi > 35 Then Exit Sub
Else
If OptionButton1 = True Then
If OptionButton2 = True Then
h = Cells(gj + 7, 21)
Cells(gj + 7, 11) = Cells(gj + 7, 11) - TextBox5
c = Cells(gj + 7, 21)
Cells(gj + 7, 15) = Cells(gj + 7, 15) + TextBox5 + h - c
End If
End If
Next
If gi > 35 Then Exit Sub
End If 'CheckBox1
'End If