"Run-time error '1004':
PasteSpecial method of Range class failed"
This occurs on the first use of a macro I use in a work book that maintains a pretty large database whenever I make changes to the macro. It only occurs once and then it is no longer an issue. I can close and reopen the workbook and not encounter this error again until I make a change to the workbook. It's very strange.
The macro takes data entered into one sheet vertically in the same column and transposes it before pasting it into another sheets row on a table.
To prevent people from breaking the workbook I have the sheets protected (but the macro removes protection to do what it needs to do before re-enabling it)
Additionally I have used some code on the entire workbook to disable cut and click/drag functions outside of the macro use.
This line of code is being highlighted for the debug error from the macro below.
This is the code I am using to disable copy/cut/drag in the workbook when the macro is not being operated.
Hopefully this is enough information to help me figure this one out... it's really got me confused lol.
Thank you in advance.
PasteSpecial method of Range class failed"
This occurs on the first use of a macro I use in a work book that maintains a pretty large database whenever I make changes to the macro. It only occurs once and then it is no longer an issue. I can close and reopen the workbook and not encounter this error again until I make a change to the workbook. It's very strange.
The macro takes data entered into one sheet vertically in the same column and transposes it before pasting it into another sheets row on a table.
To prevent people from breaking the workbook I have the sheets protected (but the macro removes protection to do what it needs to do before re-enabling it)
Additionally I have used some code on the entire workbook to disable cut and click/drag functions outside of the macro use.
This line of code is being highlighted for the debug error from the macro below.
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Code:
Sub PopulateProtect()
'
' PopulateProtect Macro
'
'
ActiveSheet.Unprotect
Sheets("Table").Select
ActiveSheet.Unprotect
Sheets("Input Worksheet").Select
Range("B12").Select
ActiveCell.FormulaR1C1 = "=NOW()"
Range("B3:B12").Select
Selection.Copy
Sheets("Table").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Input Worksheet").Select
Range("B3:B10").Select
Selection.ClearContents
Range("B3").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
This is the code I am using to disable copy/cut/drag in the workbook when the macro is not being operated.
Code:
Private Sub Workbook_Activate()
'' When making this the active workbook - run this code
' Defines variable
Dim oCtrl As Office.CommandBarControl
'Disable all Cut menus
For Each oCtrl In Application.CommandBars.FindControls(ID:=21)
oCtrl.Enabled = False
Next oCtrl
'Disable all Copy menus
For Each oCtrl In Application.CommandBars.FindControls(ID:=19)
oCtrl.Enabled = False
Next oCtrl
' Prevent Drag and Drop
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
'' When making another workbook the active workbook - run this code
' Define variable
Dim oCtrl As Office.CommandBarControl
'Enable all Cut menus
For Each oCtrl In Application.CommandBars.FindControls(ID:=21)
oCtrl.Enabled = True
Next oCtrl
'Enable all Copy menus
For Each oCtrl In Application.CommandBars.FindControls(ID:=19)
oCtrl.Enabled = True
Next oCtrl
' Re-enable Drag and Drop
Application.CellDragAndDrop = True
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'' When selecting cells in this workbook - run this code
' Prevent Drag and Drop, clear any copied data from the clipboard
With Application
.CellDragAndDrop = False
.CutCopyMode = False 'Clear clipboard
End With
End Sub
Hopefully this is enough information to help me figure this one out... it's really got me confused lol.
Thank you in advance.