Help plz! Sort a selected range

elea_acero_

New Member
Joined
Jan 26, 2023
Messages
5
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. MacOS
  3. Mobile
Hi I need to do a homework but I can´t understand how to it.

My teacher wants a Macro and a button.

When I press the button she wants that the button sort the selected range.
Please I need help, I hope someone can give me a hand with the code, it will be great.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Record yourself doing it with the macro recorder, it will give you the code for this.
 
Upvote 0
Yeah, but if I record the macro, it is going to be sorted ONLY the cells I select, and I want a button with a macro, that when I press it, sort the information that I select.
It´s that even possible?
 
Upvote 0
The macro recorder will give you a line that selects the range, then a second line that sorts the selection.
Remove the line that selects the range.
If stuck post in the thread the code the recorder produces.

A teacher would have given you instructions on how to create a button and assign a macro to it.
 
Upvote 0
mexican teachers are like that.

I try erasing the code but I don´t understand VBA code.
 
Upvote 0
We will help you but we won't do your homework for you as you gain nothing from it (besides it being against the forum rules).

If you can't record a macro and copy the code to the thread then I'm afraid you need to go back to the teacher as you haven't picked up enough from the lessons you've been given
 
Upvote 0
I know how it works.
I try and I got this code for trying but now I need to know how to change all the table, because it only change the column that I select.

Sub Ordenar_click_() Dim MyRange As Range, Mykey As Range Set MyRange = Application.InputBox("Selecciona el rango a ordenar", "", Type:=8) Set Mykey = Application.InputBox("Selecciona una celda de la columna", "", Type:=8) MyRange.Sort Key1:=Mykey End Sub
 
Upvote 0
Can you help me saying me how I can modify the code for modify the entire cells, and not only the column I select
 
Upvote 0
Can you help me saying me how I can modify the code for modify the entire cells
I don't understand what you are asking in the above (it would be better if you posted the actual question the teacher asked) and you still need to post the code that the recorder produced
 
Upvote 0
The below sorts all the cells in a sheet based on Column A

VBA Code:
Sub SortDataWithHeader()
Cells.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,741
Messages
6,126,610
Members
449,321
Latest member
syzer

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