###Sub or Function
Sub or Function
###Naming
Naming
Variables
###Variables
YouYou did a good job declaring all of your variables, but it's always a good idea to turn on Option Explicit
. You can have it automatically by going to Tools -> Options in the VBE and checking the Require Variable Declaration option. This way if you have any variables not defined, the compiler will let you know.
###Select Case
Select Case
###MergeCellsx
MergeCellsx
###Sub or Function
###Naming
###Variables
You did a good job declaring all of your variables, but it's always a good idea to turn on Option Explicit
. You can have it automatically by going to Tools -> Options in the VBE and checking the Require Variable Declaration option. This way if you have any variables not defined, the compiler will let you know.
###Select Case
###MergeCellsx
Sub or Function
Naming
Variables
You did a good job declaring all of your variables, but it's always a good idea to turn on Option Explicit
. You can have it automatically by going to Tools -> Options in the VBE and checking the Require Variable Declaration option. This way if you have any variables not defined, the compiler will let you know.
Select Case
MergeCellsx
Integers - integers are obsolete integers are obsolete. According to msdn VBA silently converts all integers to long
.
Integers - integers are obsolete. According to msdn VBA silently converts all integers to long
.
Integers - integers are obsolete. According to msdn VBA silently converts all integers to long
.
###MergeCellsx
In case you didn't know, a Sub
can take an argument the same way as a function -
Sub MergeCells(ByVal sheetName as String)
I see you are targeting columns 2 and 3, 5 and 6, 8 and 9. When you have something like that, it might be better to put those number in a variable or constant so that if they change, you can just change the initial value of the variable. -
Const FIRST_NAME_COLUMN As Long = 2
Const SECOND_NAME_COLUMN As Long = 3
Now every time you type in the columns, you can use the constant which will tell you what the column is supposed to contain.
Also, in this instance, you would probably be better with a long if
instead of 15 conditional loops. Maybe even the select case would belong here. When you see repeated code like that, it's an indication you can refactor it.
###MergeCellsx
In case you didn't know, a Sub
can take an argument the same way as a function -
Sub MergeCells(ByVal sheetName as String)
I see you are targeting columns 2 and 3, 5 and 6, 8 and 9. When you have something like that, it might be better to put those number in a variable or constant so that if they change, you can just change the initial value of the variable. -
Const FIRST_NAME_COLUMN As Long = 2
Const SECOND_NAME_COLUMN As Long = 3
Now every time you type in the columns, you can use the constant which will tell you what the column is supposed to contain.
Also, in this instance, you would probably be better with a long if
instead of 15 conditional loops. Maybe even the select case would belong here. When you see repeated code like that, it's an indication you can refactor it.