VBA - Select Entire Rows between 2 Named Cells

Neuner

New Member
Joined
Jul 18, 2018
Messages
18
New here and to macros in Excel. Would really appreciate your help with a sorting macro!

I have projects listed out in rows with various data in columns. I'm trying to create macro buttons that sort the projects & data.

Since I add projects to the group and didn't want to update the macros with the correct cells to sort, I've been trying to use Named Cells.

The projects I add sometimes have to be at the very beginning, very end or somewhere in the middle so I've defined upper and bottom border rows to help define in the macro where the data selection starts and stops. In the macro, I'm hoping to be able to select the entire rows between the border rows in case additional data columns are added in the future.

If I record a macro, this is the code I get;

Sub SortProjectNameA2Z()

Rows("14:149").Select
ActiveWorkbook.Worksheets("OVERALL").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("OVERALL").Sort.SortFields.Add Key:=Range( _
"A14:A149"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("OVERALL").Sort
.SetRange Range("A14:W149")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A11").Select
Application.CutCopyMode = False

End Sub

Row 14 is the entire row below the Upper Border Row = "ProjectDataFirstRow"
Row 149 is the entire row above the Lower Border Row = "ProjectDataLastRow"

I've also named the first cell of the Upper Border Row as "CellSelectionFirst" and the first cell of the Lower Border Row as "CellSelectionLast" if that helps?

I've searched as best I can but haven't found or couldn't figure out how to select entire rows between the border rows or border cells.

Thanks for the help!!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Not sure how clear I've been in my explanation but I've found and tested a way to select the entire rows between the Upper and Lower Border Rows but I haven't found a way to select "in between" them only.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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