Help With Existing Code

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. 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?

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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If you click Tools - References and scroll through them do any have missing alongside them?
 
Upvote 0
Sorted, didn't realize I had to save changes to PWB.
 
Upvote 0
Just one thing, all macros created in old office versions should work in 365?
 
Upvote 0
all macros created in old office versions should work in 365?

Most, there are a few exceptions but if your macro's were working in a version later than 2007 then you shouldn't have any issues with 365.
 
Upvote 0
Most, there are a few exceptions but if your macro's were working in a version later than 2007 then you shouldn't have any issues with 365.
i have noticed that they take a lot longer to run in 365?
 
Upvote 0

Forum statistics

Threads
1,212,929
Messages
6,110,743
Members
448,295
Latest member
Uzair Tahir Khan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top