# 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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

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

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,168,208
Messages
5,857,920
Members
431,908
Latest member
Marjie174

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

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