View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Can I automate Range.mergeCells = True?

In a VBA subroutine, I want to write something like:

Dim r as Range, s as String, n as Long
[...set up r, s and eventually n...]
r.Value = s
r.Resize(1, n).mergeCells = True

The problem is: how can I determine n, the number of colums merge?

My current workaround is to set n to a constant, namely the maximum
number of columns to merge, which I determined by inspection
beforehand. There is nothing to the right of r. I am not happy with
the "by inspection" requirement; I am actually iterating through all
rows in a large worksheet. Moreover, I want n to be the __minimum__
number of columns necessary.