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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

textme

New Member
Joined
Apr 14, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. MacOS
I figured it out. I used sort and filter. thanks for listening.:giggle:
 

smozgur

BatCoder
Joined
Feb 28, 2002
Messages
1,442
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,132,708
Messages
5,654,854
Members
418,155
Latest member
demasisi

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
Top