So I have some code located on Sheet1(Testing). It allows me to merge certain ranges on that sheet. Here it is:
Works great.
However, I want to clean things up a bit and so inserted a module. I would like to move the code from the sheet to the module and have it target just Sheet1(Testing) when run.
If sheet1(testing) is the active sheet, then it runs the code just fine. But if any other sheet is active, it runs that code on the active sheet instead of sheet1(testing), which is to be expected.
So I tried to change the code to only run on sheet1(Testing) but I believe that I am running into some syntax issues. I am still learning syntax for VBA and how everything is related.
My change was this:
But I am getting a runtime error 450, Wrong number of arguments or invalid property assignment.
Where am I messing up and why?
I ask "why" because I don't just want to be given an answer. I want to understand the reasoning behind it and be able to solve similar things in the future.
I have been doing a bunch of reading and based upon what I am reading, it appears to me that I have it correct, but I am obviously missing something.
Any thoughts?
-Spydey
Code:
Private Sub Merge()
Dim Ary As Variant
Dim Rng As Range
Dim a As Variant
Ary = Array("B23:B24", "B25:B26", "B27:B28", "B29:B30", etc etc etc ......)
For Each a In Ary
Range(a).Merge
Next a
End Sub
Works great.
However, I want to clean things up a bit and so inserted a module. I would like to move the code from the sheet to the module and have it target just Sheet1(Testing) when run.
If sheet1(testing) is the active sheet, then it runs the code just fine. But if any other sheet is active, it runs that code on the active sheet instead of sheet1(testing), which is to be expected.
So I tried to change the code to only run on sheet1(Testing) but I believe that I am running into some syntax issues. I am still learning syntax for VBA and how everything is related.
My change was this:
Code:
.....
Ary = Array(ThisWorkbook.Worksheets("Testing").Range("B23:B24", "B25:B26",etc etc etc......))
.....
But I am getting a runtime error 450, Wrong number of arguments or invalid property assignment.
Where am I messing up and why?
I ask "why" because I don't just want to be given an answer. I want to understand the reasoning behind it and be able to solve similar things in the future.
I have been doing a bunch of reading and based upon what I am reading, it appears to me that I have it correct, but I am obviously missing something.
Any thoughts?
-Spydey
Last edited: