# VBA code problem

#### Yaron Yehezkel

##### New Member
Hey guys!
what does this code means? I'm trying to figure out but bit confused.

Sub ExcelSolution()

Dim var1 As Integer
Dim var2 As Integer
Dim var3 As Integer

var1 = Sheets.Count
For var2 = 1 To var1 - 1
For var3 = var2 + 1 To var1
If Sheets(var3).Name < Sheets(var2).Name Then
Sheets(var3).Move before:=Sheets(var2)
End If
Next var3
Next var2
End Sub

Thanks for the help!

### Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

#### jasonb75

##### Well-known Member
Looks like it sorts the sheets (tabs) in your workbook into ascending order by name.

#### Yaron Yehezkel

##### New Member
Thank you very much! appreciate.

#### jasonb75

##### Well-known Member
Welcome

One point to note, if your tab names start with numbers then the results could be different to expected.

Numbers will sort as text e.g. 1, 10, 100, 2, 20, 200 rather than in proper order of 1, 2, 10, 20, 100, 200.
There might be similar problems with dates depending on how they are written, numeric dates will be similar to above, month names will sort alphabetically not chronologically.

#### Yaron Yehezkel

##### New Member
Maybe can you help me with another issue -

I have some problem with the sum function in the VBA, and for some reason i can't find the solution.

I have a data of employees and their monthly salary. At the end of each table, in each of the 5 specific sheets, is the "Montly Salary in NIS" column. I'm trying to figure out the VBA code to sum the "Montly Salary in NIS" column.
I need that the total amount of all employees monthly salary (the sum) will be placed under the column "Monthly Salary in NIS" and one cell after the last data line.

The problem is that in each sheet, where the "Monthly..." columns is, there are different number of rows and columns (because not all the employees worked all those 5 months).

Thank you!

Replies
5
Views
160
Replies
21
Views
351
Replies
1
Views
178
Replies
20
Views
1K
Replies
4
Views
280

### Forum statistics

1,129,685
Messages
5,637,809
Members
416,983
Latest member
LessThanAverageUser

### 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.

### Which adblocker are you using?

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

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