error get the range in a variable, i need sort the range by first column of the range

jamiguel77

Active Member
Joined
Feb 14, 2006
Messages
378
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
  2. Web
Hi,

i need sort the range by first column of the range (note the range have a row with header)

my Problem: myRange = Range("B17:F" & lastRow)

'Range("DataRange").Sort Key1:=Range("C1"), Order1:=xlDescending
Dim myRange As Range
Range("B17").Select
Dim lastRow As Integer
lastRow = Selection.End(xlDown).Offset(0).Row
myRange = Range("B17:F" & lastRow)
myRange.Sort Key1:=Range("B17"), Order1:=xlDescending



prueva.xlsx
BCDEF
17InterpreteNTemaCodigoProducción - Éxitos - Al Estilo
18Popular01Las Mañanitas1401Cántale a Mamá 1
19Popular02En tu día1401Cántale a Mamá 1
20Pedro Infante03Despierta1401Cántale a Mamá 1
21Vicente Fernández04Hermoso cariño1401Cántale a Mamá 1
22Gerardo Reyes05Paso a la reina1401Cántale a Mamá 1
23Vicente Fernández06Amor Eterno1401Cántale a Mamá 1
24Grupo Raíces07Madrecita, sólo tú (voz)1401Cántale a Mamá 1
25Grupo Raíces08Madrecita, sólo tú1401Cántale a Mamá 1
macro 1




Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
It should be
VBA Code:
set myRange = Range("B17:F" & lastRow)
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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