VBA code problem

Yaron Yehezkel

New Member
Joined
Jul 11, 2020
Messages
13
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Dec 30, 2008
Messages
12,637
Office Version
  1. 365
Platform
  1. Windows
Looks like it sorts the sheets (tabs) in your workbook into ascending order by name.
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,637
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Jul 11, 2020
Messages
13
Office Version
  1. 365
Platform
  1. Windows
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!
 

Watch MrExcel Video

Forum statistics

Threads
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.
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
Top