Help updating this code to sort current region by Column A then Column G?

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a code that finds a specific word and delete 3 rows above it(therefore removing blank cells between two similar ranges.) I would like to be able to select the current region and resort. Here is what I have come up with so far. This removes my columns for me but I can't figure out the rest.
VBA Code:
Sub Delete_Rows()
    Range("A" & Rows.Count).End(xlUp).Select
    Const WordToLook = "NYC"
    Dim RowWord As Long
    RowWord = Columns(4).Find(WordToLook, LookAt:=xlWhole).Row
    Rows(RowWord - 3 & ":" & RowWord - 1).Delete
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Maybe
VBA Code:
Range("A1").CurrentRegion.Sort Range("A1"), xlAscending, Range("G1"), , xlAscending, Header:=xlYes
 
Upvote 0
Maybe
VBA Code:
Range("A1").CurrentRegion.Sort Range("A1"), xlAscending, Range("G1"), , xlAscending, Header:=xlYes
Hey Fluff, thank you, this one isn't working though. The issue that I'm having is that my sheet is going to have spaces so I do not want to select the whole sheet. I only want to Ctrl + * to highlight my current range and sort that one only as the other ranges I need to leave untouched.
 
Upvote 0
What is your current range?
 
Upvote 0
What is your current range?
Should have used XL2BB to begin with. This is a similar format but the ranges will vary in length, but I would like to go from this:

Order Template.xlsx
ABCDEFGHI
1Order RecipientPrimary AddressSecondary AddressCityCity, State, Zip CodePrimary OrderSecondary OrderThird Order
2Jane Doe 1123 Lets Do ItGetting ThereNJ 123 Lets Do it, Getting There, NJ456124512345699
3Jane Doe 2124 Lets Do ItGetting ThereNJ 124 Lets Do it, Getting There, NJ456134512345699
4Jane Doe 3125 Lets Do ItGetting ThereNJ 125 Lets Do it, Getting There, NJ456144512345699
5
6
7
8John Doe 1123 Make it Happen150 We Did ItNew YorkManhattan, NY, 10001125455456875854
9Blake Doe124 Make it Happen151 We Did ItNew YorkManhattan, NY, 10002125465456975854
10John Doe 3125 Make it Happen152 We Did ItNew YorkManhattan, NY, 10003125475457075854
11John Doe 4126 Make it Happen153 We Did ItNew YorkManhattan, NY, 10004125485457175854
12John Doe 5127 Make it Happen154 We Did ItNew YorkManhattan, NY, 10005125495457275854
13John Doe 6128 Make it Happen155 We Did ItNew YorkManhattan, NY, 10006125505457375854
14
15
16
17Ann Doe129 Make it HappenNYCManhattan, NY, 10007125515457475854
18John Doe 8130 Make it HappenNYCManhattan, NY, 10008125525457575854
19John Doe 9131 Make it HappenNYCManhattan, NY, 10009125535457675854
20
Sheet30


To this

Order Template.xlsx
ABCDEFGHI
8Ann Doe129 Make it HappenNYCManhattan, NY, 10007125515457475854
9Blake Doe124 Make it Happen151 We Did ItNew YorkManhattan, NY, 10002125465456975854
10John Doe 1123 Make it Happen150 We Did ItNew YorkManhattan, NY, 10001125455456875854
11John Doe 3125 Make it Happen152 We Did ItNew YorkManhattan, NY, 10003125475457075854
12John Doe 4126 Make it Happen153 We Did ItNew YorkManhattan, NY, 10004125485457175854
13John Doe 5127 Make it Happen154 We Did ItNew YorkManhattan, NY, 10005125495457275854
14John Doe 6128 Make it Happen155 We Did ItNew YorkManhattan, NY, 10006125505457375854
15John Doe 8130 Make it HappenNYCManhattan, NY, 10008125525457575854
16John Doe 9131 Make it HappenNYCManhattan, NY, 10009125535457675854
17
18
Sheet30
 
Upvote 0
I am now totally confused, you said you wanted to sort the current region, but your mini-sheets shows you want to sort the used range. :unsure:
Also what has happened to the header row?
 
Upvote 0
I am now totally confused, you said you wanted to sort the current region, but your mini-sheets shows you want to sort the used range. :unsure:
Also what has happened to the header row?
Fluff, Sorry for the confusion. I interpreted Current.Region to mean the same as "Ctrl + *" I guess I'm indeed referring to used range.

This is essentially going to be one macro within a macro, and once I figure this last piece out I'm hoping in a new thread you guys can help me optimize it because it is far from perfect. But to answer your question my supervisor does not need the header row in every used range he just wants it so NYC and New York do not get split up and get sorted by "A" then "G" hope that explains it a bit more. If not I can show a larger XL2BB sheet.
 
Upvote 0
Ok, how about
VBA Code:
ActiveSheet.UsedRange.Sort Range("A1"), xlAscending, Range("G1"), , xlAscending, Header:=xlYes
 
Upvote 0
Ok, how about
VBA Code:
ActiveSheet.UsedRange.Sort Range("A1"), xlAscending, Range("G1"), , xlAscending, Header:=xlYes
Fluff, once again I feel like an idiot because I did not answer your question properly.

I now realized that my X2LBB code omitted the range with NJ. Ideally I would like this code to just sort the used range without touching NJ or any other city I may have.
 
Upvote 0
I have no idea what you are talking about.
Please explain clearly & succinctly what you are trying to do.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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