View Single Post
  #17   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Method 'Range' of Object_Worksheet Failed

the value for a merged cell is stored in the upper left corner of the merged
area. If (for example), C11 were in a merged area B11:D11, then the value
would need to be written to B11. I can only guess, but

set rng = ws2.Cells(baserow1,2+k)
rng.Value = "NA"
rng.offset(16,0).Value = "NA"
rng.offset(0,7).value = "NA"
rng.offset(16,7).value = "NA"

would be
at the top add
Dim rngArr(1 to 4) as Range
Dim LL as Long

then replace the above with

set rng = ws2.cells(baserow1,2+k)
set rngArr(1) = rng
set rngArr(2) = rng.offset(16,0)
set rngArr(3) = rng.offset(0,7)
set rngArr(4) = rng.offset(16,7)
for LL = 1 to 4
set rng = rngArr(LL).mergeArea(1)
rng.Value = "NA"
next


to demo from the immediate window

B9 is not merged
? Range("B9").MergeArea(1).Address
$B$9

Now merge the area A9 to C10 (included B9)
range("A9:C10").Merge

Now test with B9 in a merge area
? Range("B9").MergeArea(1).Address
$A$9

so the data would be written to A9 in this case which should work if this is
the nature of the problem.

--
Regards,
Tom Ogilvy


"Excel-erate2004 " wrote in
message ...
Hi Tom,

Your most recent suggestion seems to be working!! I'll have to do
further tesing on it for various situations, But I'm very hopeful,
thanks all due to your help!

I have yet to take a long hard look at your posted Test code as I'm
still testing with the main project, but that will be a big asset as I
try and figure out just whats going on there.

One minor thing that I have to figure out is, an "NA" tag is not being
placed in a group of merged cells. These merged cells are at the
bottom of the tables and I just choose to represent it by a single cell
in the ranges that I had given in a text file. Its the
CheckboxPelagicL item in the array.

Its strange but it works for the 1st and 3rd range but not the 2nd and
4th.

Where in the code would I go to adjust this so that these cells are
encompassed and the NA tag is applied as required by the checkboxes in
the array.

Thanks again for your amazing help!

P.S. I hope this is the last time I have to bother you with a
question.


---
Message posted from http://www.ExcelForum.com/