在不受保护和受保护的工作表中实现代码 VBA Excel



当我尝试执行此代码时,它只执行Exit Sub之后的部分,当工作表不受保护时,仅执行foreach循环。我认为这是由Exit Sub引起的.我的问题是我想在工作表受保护时执行不同的代码(for each cell in Range("B6:B112..((,另一个(从Dim rng as Range开始......我试过If..Then..Else但这不起作用。

Private Sub Worksheet_Change(ByVal Target As Range)
If Worksheets("test").ProtectContents Then Exit Sub
For Each cell In Range("B6:B112")
If cell.Value <> "" Then
cell.EntireRow.Hidden = False
Else
cell.EntireRow.Hidden = True
End If
Next cell
Dim rng As Range
Dim eingabeNr As Double, letzteZeile As Long, eingabeDatum As String, eingabeNrString As String
Set rng = Range("D:BC")

感谢。

Private Sub Worksheet_Change(ByVal Target As Range)
If Worksheets("test").ProtectContents = True Then 'added = true for readability.
For Each cell In Range("B6:B112")
If cell.Value <> "" Then
cell.EntireRow.Hidden = False
Else
cell.EntireRow.Hidden = True
End If
Next cell
Else
Dim rng As Range
Dim eingabeNr As Double, letzteZeile As Long, eingabeDatum As String,_
eingabeNrString As String
Set rng = Range("D:BC")
Do some stuff here
End if

相关内容

  • 没有找到相关文章

最新更新