Consulting

Results 1 to 2 of 2

Thread: Solved: locked method of range failed

  1. #1
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location

    Solved: locked method of range failed

    [VBA]Sub replaceformulas()
    Dim wb As Workbook
    Dim lr As Long
    For Each wb In Application.Workbooks
    If wb.name <> ThisWorkbook.name Then
    If Not InStr(wb.name, "May Meter") Then
    wb.Sheets(1).Activate
    lr = Range("A" & Rows.Count).End(xlUp).Row

    replaceformulas2 lr
    End If
    End If
    Next wb
    End Sub
    Private Sub replaceformulas2(lr As Long)

    Range("AB2").Formula = "=IF((X2-V2)-U2>0,(X2-V2)-U2,0)"
    Range("AB2").AutoFill Destination:=Range("AB2:AB" & lr), Type:=xlFillDefault
    Range("AD2").Formula = "=AB2*AC2"
    Range("AD2").AutoFill Destination:=Range("AD2:AD" & lr), Type:=xlFillDefault
    'Range("B2:G" & lr & ",AA2:AD" & lr & "AL2:AL" & lr).Locked = True
    'ActiveSheet.Protect

    End Sub[/VBA]

    trying to cycle through 50 workbooks and replace the formulas and lock the ranges but the locked property is not working
    ------------------------------------------------
    Happy Coding my friends

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [VBA]Private Sub replaceformulas2(lr As Long)

    Range("AB2").Formula = "=IF((X2-V2)-U2>0,(X2-V2)-U2,0)"
    Range("AB2").AutoFill Destination:=Range("AB2:AB" & lr), Type:=xlFillDefault
    Range("AD2").Formula = "=AB2*AC2"
    Range("AD2").AutoFill Destination:=Range("AD2:AD" & lr), Type:=xlFillDefault
    With Sheets("Sheet1")
    .Unprotect
    .Cells.Locked = False
    .Range("B2:G" & lr & ", AA2:AD" & lr & ", AL2:AL" & lr).Locked = True
    .Protect Contents:=True
    End With

    End Sub[/VBA]
    ------------------------------------------------
    Happy Coding my friends

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •