Union is a function. When you use the
Union function, you are telling it that you want to concatenate
pointers to two ranges, which are represented by the two parameters of the function. It is not one parameter with the literal text of the ranges. The comma separates the parameters of the function. You only need to use
Union to concatenate the pointers, nothing else.
If you're looking to concatenate just two pointers that have been saved to vars
r1 and
r2:
Code: Select all
r1 := xl.Range("F6")
r2 := xl.Range("G7")
Range := xl.Union[r1,r2]
Range.Font.Bold := True
The variable
Range now contains a pointer to both ranges. It is functionally the equivalent of doing this:
xl.Range["F6,G7"]
The difference is that
Range will only accept 34 comma separated ranges (as noted above). I don't know
Union's limitations, but if there is one it's beyond 60,000 pointers, which is more than most people would ever need.
You can also continually concatenate pointers to one variable:
Code: Select all
Range := xl.Range("F6")
Range := xl.Union[Range,xl.Range("G7")]
Range := xl.Union[Range,xl.Range("H8")]
Range.Font.Bold := True ; Range contains pointers to cells F6, G7 and H8
Does this make more sense?