How to sort a range but ignore blanks with vba?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a range which I use for data (b2:j35)

Data not always down to row 35 so when i sort by column J (Largest to Smallest) its putting blanks to the top

Anyone have a solution to this?
Much appreciated
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
so delete all rows with blanks currently at the bottom, then sort again large to small - or - use vba to "move" the blanks to the bottom, then sort only the non blanks - seems like a sledgehammer to crack a nut.
 
Upvote 0
9original data1
83
7
65
5
47
38
2
12
4
6
9
this macro achieves what I think you want
after first part of macro
For j = 1 To 121
For k = j + 1 To 133
If Cells(j, 1) = "" Then temp = Cells(j, 1): Cells(j, 1) = Cells(k, 1): Cells(k, 1) = temp5
Next k7
Next j8
For a = 1 To 132
If Cells(a, 1) = "" Then tot = tot + 14
Next a6
For z = 1 To 139
For b = 1 To 13 - tot - 1
c = b + 1
If Cells(c, 1) > Cells(b, 1) Then temp = Cells(b, 1): Cells(b, 1) = Cells(c, 1): Cells(c, 1) = temp
Next b
Next z
End Sub

<colgroup><col span="9"><col><col span="4"></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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