Hello,
I have a macro that works as needed. The sheet has form buttons I want to protect but when I unlock cells A10 to M50 and protect the sheet I receive error 1004 saying a cell its trying to write to is protected and read only.
I'm not sure what I'm missing.
Any help will be appreciated
Thank you
Sub Macro1()
'
' Macro1 Macro
' Clear and upload new cal report
'
'
Range("A10:M50").Select
Selection.ClearContents
'
' Macro1 Macro
' Read text file
'
Dim vFilename As Variant
vFilename = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt", _
Title:="Select Text File", _
ButtonText:="Select", _
MultiSelect:=False)
If vFilename = False Then Exit Sub 'user cancelled
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & vFilename, Destination:=Range("$N$10"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(15, 10, 13, 12, 1, 6, 7, 7, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:K").Select
Range("K1").Activate
Selection.Delete Shift:=xlToLeft
End Sub
I have a macro that works as needed. The sheet has form buttons I want to protect but when I unlock cells A10 to M50 and protect the sheet I receive error 1004 saying a cell its trying to write to is protected and read only.
I'm not sure what I'm missing.
Any help will be appreciated
Thank you
Sub Macro1()
'
' Macro1 Macro
' Clear and upload new cal report
'
'
Range("A10:M50").Select
Selection.ClearContents
'
' Macro1 Macro
' Read text file
'
Dim vFilename As Variant
vFilename = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt", _
Title:="Select Text File", _
ButtonText:="Select", _
MultiSelect:=False)
If vFilename = False Then Exit Sub 'user cancelled
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & vFilename, Destination:=Range("$N$10"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(15, 10, 13, 12, 1, 6, 7, 7, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:K").Select
Range("K1").Activate
Selection.Delete Shift:=xlToLeft
End Sub