Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Agregue Bloquear celdas / rangos a un código VBA existente para crear áreas editables y permitir que VBA se ejecute

No he usado VBA antes, así que soy realmente nuevo en esto :-) El siguiente es el código que estoy usando actualmente, y simplemente necesito bloquear todas las áreas de la hoja (sin usar el nombre de la hoja) además de A13: A377, B1, D3:D4, D13:D377, F13:I377. No puedo proteger la hoja porque el VBA no funcionará. Ayuda por favor...

 Private Sub Worksheet_Change(ByVal Target As Range) ' To allow multiple selections in a Drop Down List in Excel (without repetition) Dim Oldvalue As String Dim Newvalue As String Application.EnableEvents = True On Error GoTo Exitsub If Target.Column = 1 Then If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then GoTo Exitsub Else: If Target.Value = "" Then GoTo Exitsub Else Application.EnableEvents = False Newvalue = Target.Value Application.Undo Oldvalue = Target.Value If Oldvalue = "" Then Target.Value = Newvalue Else If InStr(1, Oldvalue, Newvalue) = 0 Then Target.Value = Oldvalue & " & " & Newvalue Else: Target.Value = Oldvalue End If End If End If End If Application.EnableEvents = True Exitsub: Application.EnableEvents = True End Sub
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

desbloquear celdas y proteger hoja

¡No veo ninguna relación entre tu descripción y el código que has compartido! A continuación encontrará una propuesta para desbloquear una unión de celdas y proteger la hoja (¡sin contraseña!)

 Option Explicit Sub UnlockCells_and_Protect() Dim actSheet As String actSheet = "Sheet2" ' choose whatever you need 'actSheet = ActiveSheet.Name 'actSheet = Sheets(3).Name 'actsheet = "SpecialSheet" Call UnprotectSheet(actSheet) Call LockAll(actSheet) Call UnlockRange(actSheet, "A13:A377,B1,D3:D4,D13:D377,F13:I377") Call ProtectSheet(actSheet) End Sub Sub UnlockRange(sheetName As String, RangeReference As String) With Sheets(sheetName).Range(RangeReference) .Locked = False .FormulaHidden = False 'you might want to mark the unlocked cells for debugging Sheets(sheetName).Range(RangeReference).Interior.Color = vbYellow End With End Sub Sub ProtectSheet(sheetName As String) Sheets(sheetName).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub Sub ProtectActiveSheet() ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub Sub UnprotectSheet(sheetName As String) Sheets(sheetName).Unprotect End Sub Sub UnprotectActiveSheet() ActiveSheet.Unprotect End Sub Sub LockAll(sheetName As String) Sheets(sheetName).Cells.Locked = True Sheets(sheetName).Cells.FormulaHidden = False 'if you marked the unlocked cells yellow you change 'them back to white with lock/unlock all Sheets(sheetName).Cells.Interior.Color = vbWhite End Sub Sub UnlockAll(sheetName As String) Sheets(sheetName).Cells.Locked = False Sheets(sheetName).Selection.FormulaHidden = False 'if you marked the unlocked cells yellow you change 'them back to white with lock/unlock all Sheets(sheetName).Cells.Interior.Color = vbWhite End Sub
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!