stillenacht
New Member
- Joined
- Nov 16, 2015
- Messages
- 6
I am having a problem running a macro I originally created in one workook in other workbooks. The code is a simple copy paste, remove duplicates, and sort alphabetically. However, I want to be able to run it without the original workbook open. I put it in VBA Project (PERSONAL.XLSB), but when I attempt to run it in the "Macros" menu of another workbook, it outputs:
Run-time error '424':
Object Required
How do I get it to recognize it should use the code on my new workbook automatically?
Here is the code:
Sub ArrangePrices()
'For formatting realtimedata into readable format
'Copy each sheet to first sheet
Sheet2.Range("A1:B2000").Copy
Sheets("Sheet1").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet3.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("C1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet4.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("D1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet5.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("E1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet6.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("F1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet7.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("G1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Insert Headers
[B1].Value = 1000
[C1].Value = 1100
[D1].Value = 1200
[E1].Value = 1300
[F1].Value = 1400
[G1].Value = 1500
'Remove Duplicates
ActiveSheet.Range("A1:G2000").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
'Sort Alphabetically
With Sheets("Sheet1")
.Range("A2:G2000").Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End With
End Sub
Run-time error '424':
Object Required
How do I get it to recognize it should use the code on my new workbook automatically?
Here is the code:
Sub ArrangePrices()
'For formatting realtimedata into readable format
'Copy each sheet to first sheet
Sheet2.Range("A1:B2000").Copy
Sheets("Sheet1").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet3.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("C1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet4.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("D1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet5.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("E1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet6.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("F1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheet7.Range("B1:B2000").Copy
Sheets("Sheet1").Activate
Range("G1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Insert Headers
[B1].Value = 1000
[C1].Value = 1100
[D1].Value = 1200
[E1].Value = 1300
[F1].Value = 1400
[G1].Value = 1500
'Remove Duplicates
ActiveSheet.Range("A1:G2000").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
'Sort Alphabetically
With Sheets("Sheet1")
.Range("A2:G2000").Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End With
End Sub