VBA - Run-time error 1004

Sam Clough

New Member
Joined
Feb 9, 2014
Messages
44
Office Version
  1. 365
Platform
  1. Windows
quote_icon.png
Originally Posted by Sam Clough
I have a large (10MB) file for rankings of sport on Excel 2016. It has a "button" for various sortings. Out of the blue when using this button I get Run-time error '1004' To do this, all the merged cells need to be the same size. As I am not good on these macros, I need urgent help. Can I upload the file for someone to maybe assist. I am desperate.



You need to start your own thread and maybe somebody will pick up on it. This thread deals with a different issue. The 1004 error code can be for various causes, usually related to user coding error like misspelled words, erroneous syntax, etc.

This is what Debug shows:
ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("A7"), Order1:=xlDescending, _
Key2:=Range("F7"), Order2:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub


Private Sub CommandButton3_Click()


'sort male state


ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("A7"), Order1:=xlDescending, _
Key2:=Range("E7"), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub


Private Sub CommandButton4_Click()


'sort female name


ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("A7"), Order1:=xlAscending, _
Key2:=Range("C7"), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub


Private Sub CommandButton5_Click()


'sort female points


ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("A7"), Order1:=xlAscending, _
Key2:=Range("F7"), Order2:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub


Private Sub CommandButton6_Click()


'sort female state


ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("A7"), Order1:=xlAscending, _
Key2:=Range("E7"), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub


Private Sub CommandButton7_Click()
'sort overall points


ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("F7"), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells




End Sub


Private Sub CommandButton8_Click()


'sort overall names




ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("C7"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub


Private Sub CommandButton9_Click()


'sort overall state


ActiveSheet.Unprotect
Range("A7:AZZ3050").Sort _
Key1:=Range("E7"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have formed the impression this is posted from another site as to his initial cause, the way it has been presented doesn't help his needs.

Sam UNMERGE your cells. If you must merge for visual clarity use Centre across selection from the format menu.

Identify EXACTLY where the code stops
 
Upvote 0
Thank you. I have learned that I added some rows at top which threw everything out of kilta. Thank you for your assistance.
 
Upvote 0

Forum statistics

Threads
1,216,127
Messages
6,129,024
Members
449,482
Latest member
al mugheen

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