Sorting problem

textme

New Member
Joined
Apr 14, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. MacOS
Have a sort macro. sorting 4 columns and a variable number of rows. Rows change weekly. How do i change to only select rows with data in?
this is my current macro which puts me in an endless loop.
Do While Not IsEmpty(ActiveCell)
Range("A2:D40").Select
Range("D2").Activate
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range("D6:D40") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A2:D40")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Loop

Range("A2").Select
End Sub
I am a novice, excuse my ignorance
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I figured it out. I used sort and filter. thanks for listening.:giggle:
 
Upvote 0
Welcome to the MrExcel Message Board!

If you modified your code to solve this problem, then please paste the final code then it is perfectly fine to mark your own post as the solution as it will help future readers.
Or did you actually use sort and filter Excel functions and gave up using VBA?

In either case, the post that you marked as the solution is not the solution of the original question, that's why I removed the solution marker.
 
Upvote 0

Forum statistics

Threads
1,215,067
Messages
6,122,949
Members
449,095
Latest member
nmaske

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