Sheet1 VBA Code
Sheet1 VBA Code
With Me
.Protect Password:=SheetPassword, UserInterfaceOnly:=True, _
AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, _
AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
AllowDeletingColumns:=True, AllowDeletingRows:=True, _
AllowSorting:=True, AllowFiltering:=True,
AllowUsingPivotTables:=True
End With
Exit Sub
ErrorHandler:
Debug.Print "ProtectSheet error: " & Err.Description
' Fallback to basic protection
Me.Protect Password:=SheetPassword
End Sub
Set ws = ThisWorkbook.Sheets("Sheet1")
CleanUp:
ProtectSheet
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox "Error in HandleSheetSetup: " & Err.Description, vbCritical
Resume CleanUp
End Sub
Set ws = ActiveSheet
numRows = CLng(response)
addInTable = MsgBox("Add the rows within the table?", vbYesNo + vbQuestion,
"Add to Table")
CleanUp:
mblnPerformingRowOperation = False
mblnSkipNextChangeEvent = False
ProtectSheet
Application.ScreenUpdating = True
End Sub
Set ws = ThisWorkbook.Sheets("Sheet1")
selectedRow = Selection.Row
numRows = CLng(response)
CleanUp:
mblnPerformingRowOperation = False
mblnSkipNextChangeEvent = False
ProtectSheet
Application.ScreenUpdating = True
End Sub
If showMessage Then
Application.EnableEvents = False
On Error Resume Next
Application.Undo
On Error GoTo 0
Application.EnableEvents = True
End If
Set ws = ThisWorkbook.Sheets("Sheet1")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastCol = 11 ' Column K
Set rng = ws.Range("A1").Resize(lastRow, lastCol)
rng.Borders.LineStyle = xlNone
Application.ScreenUpdating = False
For Each cell In rng
If Trim(cell.Value) <> "" Then
With cell.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
End If
Next cell
CleanUp:
ProtectSheet
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox "Error in AddBorders: " & Err.Description, vbCritical
Resume CleanUp
End Sub
ThisWorkbook.Sheets("Sheet1").Range("E4").Value = Date
CleanUp:
ProtectSheet
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox "Error updating date: " & Err.Description, vbCritical
Resume CleanUp
End Sub
Set ws = ThisWorkbook.Sheets("Sheet1")
Set emptyRows = New Collection
CancelSave = False
hasErrors = False
' Check for partially filled rows (all cells empty except one)
For Each cell In rng
If Application.CountA(rng.Rows(cell.Row - rng.Row + 1)) = 1 And _
cell.Value = "" Then
emptyRows.Add cell.Row
hasErrors = True
End If
Next cell
Next tbl
CleanUp:
ProtectSheet
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox "Validation error: " & Err.Description, vbCritical
CancelSave = True
Resume CleanUp
End Sub