0
下面的代碼是針對我已經工作了幾個月的多頁價格表。基本上,每個部門在工作表中有三個頁面:包含所有數據的「Mstr」頁面,帶有用於數據選擇的活動X控件的「Rate Adj」頁面以及顯示選擇結果的輸出頁面。我所有其他部門的宏都運行良好。這一個正在工作。它出於某種原因已經開始鎖定,我無法弄清楚原因。該部門有4個產品類型複選框,1個復位複選框和1個價格調整按鈕,用於折扣價格。所有頁面都是安全的並且有密碼保護我已經包含了一種產品類型複選框的代碼以及重置複選框和速率調整按鈕。VBA宏鎖定Excel,宏沒有完成,正在工作
Private Sub CheckBox230_Click()
If CheckBox230.Value = True Then
Sheets("Mstr_Chem").Unprotect Password:="jeff"
Sheets("Chemicals").Unprotect Password:="jeff"
Dim allviscells As Range
Dim lastrow As Long
With Sheets("Mstr_Chem")
.Range("A5:O250").AutoFilter Field:=1, Criteria1:="=400"
.Range("A5:O250").AutoFilter Field:=14, Criteria1:="=Active"
.Columns("C").Hidden = True
.Columns("D").Hidden = True
.Columns("E").Hidden = True
.Columns("I").Hidden = True
.Columns("J").Hidden = True
.Columns("K").Hidden = True
.Columns("L").Hidden = True
.Columns("M").Hidden = True
.Columns("N").Hidden = True
Set allviscells = Sheets("Mstr_Chem").Range("A6:O250").SpecialCells(xlCellTypeVisible)
allviscells.Copy
lastrow = Sheets("Chemicals").Range("A250").End(xlUp).row
Sheets("Chemicals").Cells(lastrow + 1, 1).PasteSpecial xlPasteValues
Sheets("Chemicals").Cells(lastrow + 1, 1).PasteSpecial xlPasteFormats
Sheets("Chemicals").Range("A6:F250").WrapText = False
Sheets("Chemicals").Columns("A:F").AutoFit
Sheets("Chemicals").Range("G6:G250").WrapText = True
End With
End If
Sheets("Mstr_Chem").Protect Password:="jeff"
Sheets("Chemicals").Protect Password:="jeff"
End Sub
Private Sub CommandButtonRateAdj3_Click()
Sheets("Chemicals").Unprotect Password:="jeff"
Dim rng As Range, cell As Range
Set rng = Sheets("Chemicals").Range("F6:F200")
Set Y = Sheets("Rate Adj").Range("D22")
For Each cell In rng
If IsNumeric(cell.Value) Then
cell.Value = Round((cell.Value - (Y * cell.Value)), 0)
End If
If Not IsNumeric(cell.Value) Then
cell.Value = cell.Value
End If
If cell.Value < 1 Then
cell.Value = Null
End If
Next cell
Sheets("Chemicals").Protect Password:="jeff"
End Sub
Private Sub CheckBox234_Click()
Sheets("Mstr_Chem").Unprotect Password:="jeff"
If CheckBox234.Value = True Then
Sheets("Mstr_Chem").Cells.AutoFilter
CheckBox230.Value = False
CheckBox230.Enabled = False
CheckBox231.Value = False
CheckBox231.Enabled = False
CheckBox232.Value = False
CheckBox232.Enabled = False
CheckBox233.Value = False
CheckBox233.Enabled = False
Sheets("Rate Adj").Range("D22").Value = Null
End If
If CheckBox234.Value = False Then
CheckBox230.Enabled = True
CheckBox231.Enabled = True
CheckBox232.Enabled = True
CheckBox233.Enabled = True
With Sheets("Mstr_Chem")
.Columns("C").Hidden = False
.Columns("D").Hidden = False
.Columns("E").Hidden = False
.Columns("I").Hidden = False
.Columns("J").Hidden = False
.Columns("K").Hidden = False
.Columns("L").Hidden = False
.Columns("N").Hidden = False
.Columns("O").Hidden = False
End With
End If
Sheets("Mstr_Chem").Protect Password:="jeff"
Sheets("Chemicals").Unprotect Password:="jeff"
Sheets("Chemicals").Range("A6:Z150").Value = Null
Sheets("Chemicals").Range("A6:Z150").ClearFormats
Sheets("Chemicals").Protect Password:="jeff"
End Sub
。您需要一個模塊級別標誌變量,您可以設置該變量以使每個控件的代碼在被另一個控件更改時簡單地退出。 – Rory 2015-02-23 12:56:27
@Rory假設這是問題,禁用事件是否也解決了這個問題? – eirikdaude 2015-02-23 13:58:00
@eirikdaude否 - 禁用事件對用戶窗體上的控件沒有影響。你必須使用自己的變量來達到類似的效果。 – Rory 2015-02-23 14:00:45