Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,748
- Office Version
- 365
- Platform
- Windows
I have been using this code below for some time and works great. I have now upgraded to 365 and I get an Compile error: Can't find project or library and points to mySource = (3rd row down)
What can be done please?
What can be done please?
Code:
Sub CopyAndInsertRow()
'Copies selected rows and inserts amount you want entered in input box, then sorts by column C.
Set mySource = Selection.EntireRow
mySource.Copy
selectedrowscount = mySource.Rows.Count
Dim x As Long, y As Long
x = mySource.Row
Dim t
t = InputBox("Enter Number Of Times Selected Row(s) To Be Copied.", "Number of Copies", 1)
If t = 0 Or t = "" Then Exit Sub
y = x + t * selectedrowscount - 1
Rows(x & ":" & y).Insert Shift:=xlDown
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("C1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Rows(x & ":" & y + selectedrowscount)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.CutCopyMode = False
End Sub