Schmendlow
Schmendlow

Reputation: 21

Sorting target rows alphabetically by first Cell using VBA

It's probably not that complex of an issue but I still didn't succeed:

I have an Excel list of 6 variables starting at the range of "B14:G14", where in column "B" you have a name and in the columns "C:G" you have formulas that are ment to be connected to that very name. I created a button using VBA to simplify adding additional name&formula complexes into the rows below, so the list does have kind of an open end.

What I would like to do now, is create another button using VBA that sorts the rows ("B:G") alphabetically by the name in the first column ("B"). Example:

  B       C     D     E     F     G

Gamma   =1+1  =2+2  =3+3  =4+4  =5+5
Alpha   =6+6  =7+7  =8+8  =9+9  =1+2
Beta    =1+3  =1+4  =1+5  =1+6  =1+7

Button1_Click

  B       C     D     E     F     G

Alpha   =6+6  =7+7  =8+8  =9+9  =1+2
Beta    =1+3  =1+4  =1+5  =1+6  =1+7
Gamma   =1+1  =2+2  =3+3  =4+4  =5+5

It'd be awesome if anybody could help me out with this! Thanks a lot!

Upvotes: 0

Views: 2898

Answers (1)

Kyle
Kyle

Reputation: 2545

You will use the Sort method of the Range object.

Range("B:G").Sort Key1:=Range("B:B"), Order1:=xlAscending

Upvotes: 1

Related Questions