PC Review


Reply
Thread Tools Rate Thread

Dealing with merged cells

 
 
Chrisso
Guest
Posts: n/a
 
      12th Jun 2007
I have a range name for a cell of MYNAME.

MYNAME started off life just being a single cell and I could do all
sorts of wonderful things to it concisely:

Range("MYNAME").ClearContents
Range("MYNAME").Locked = True

I have now made MYNAME a merged cell that spans two columns (A1:B1).
Now I find for my code to work I have to select the merged cells first
then perform my operations:

Range("MYNAME").Select
Selection.ClearContents
Selection.Locked = True

Is there a way to deal with merged cells so that I can perform the
above operations with just one line of code to make the code easier to
read and follow?

Chrisso

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      12th Jun 2007
I'd probably do it this way

Sub Test()

With Range("MYNAME").MergeArea
.ClearContents
.Locked = True
End With

End Sub

HTH,
Barb Reinhardt
"Chrisso" wrote:

> I have a range name for a cell of MYNAME.
>
> MYNAME started off life just being a single cell and I could do all
> sorts of wonderful things to it concisely:
>
> Range("MYNAME").ClearContents
> Range("MYNAME").Locked = True
>
> I have now made MYNAME a merged cell that spans two columns (A1:B1).
> Now I find for my code to work I have to select the merged cells first
> then perform my operations:
>
> Range("MYNAME").Select
> Selection.ClearContents
> Selection.Locked = True
>
> Is there a way to deal with merged cells so that I can perform the
> above operations with just one line of code to make the code easier to
> read and follow?
>
> Chrisso
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      12th Jun 2007
I is unclear if the definition of myname is 1 cell or 2, but if it is
actually defined to be two cells or could be two cells, then I would alter it
as such:


Sub Test()

With Range("MYNAME")(1).MergeArea
.ClearContents
.Locked = True
End With

End Sub

--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote:

> I'd probably do it this way
>
> Sub Test()
>
> With Range("MYNAME").MergeArea
> .ClearContents
> .Locked = True
> End With
>
> End Sub
>
> HTH,
> Barb Reinhardt
> "Chrisso" wrote:
>
> > I have a range name for a cell of MYNAME.
> >
> > MYNAME started off life just being a single cell and I could do all
> > sorts of wonderful things to it concisely:
> >
> > Range("MYNAME").ClearContents
> > Range("MYNAME").Locked = True
> >
> > I have now made MYNAME a merged cell that spans two columns (A1:B1).
> > Now I find for my code to work I have to select the merged cells first
> > then perform my operations:
> >
> > Range("MYNAME").Select
> > Selection.ClearContents
> > Selection.Locked = True
> >
> > Is there a way to deal with merged cells so that I can perform the
> > above operations with just one line of code to make the code easier to
> > read and follow?
> >
> > Chrisso
> >
> >

 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      12th Jun 2007
Tom,

What's the difference between

Range("MYNAME")(1).MergeArea

and

Range("MYNAME").MergeArea

Thanks,
Barb

"Tom Ogilvy" wrote:

> I is unclear if the definition of myname is 1 cell or 2, but if it is
> actually defined to be two cells or could be two cells, then I would alter it
> as such:
>
>
> Sub Test()
>
> With Range("MYNAME")(1).MergeArea
> .ClearContents
> .Locked = True
> End With
>
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Barb Reinhardt" wrote:
>
> > I'd probably do it this way
> >
> > Sub Test()
> >
> > With Range("MYNAME").MergeArea
> > .ClearContents
> > .Locked = True
> > End With
> >
> > End Sub
> >
> > HTH,
> > Barb Reinhardt
> > "Chrisso" wrote:
> >
> > > I have a range name for a cell of MYNAME.
> > >
> > > MYNAME started off life just being a single cell and I could do all
> > > sorts of wonderful things to it concisely:
> > >
> > > Range("MYNAME").ClearContents
> > > Range("MYNAME").Locked = True
> > >
> > > I have now made MYNAME a merged cell that spans two columns (A1:B1).
> > > Now I find for my code to work I have to select the merged cells first
> > > then perform my operations:
> > >
> > > Range("MYNAME").Select
> > > Selection.ClearContents
> > > Selection.Locked = True
> > >
> > > Is there a way to deal with merged cells so that I can perform the
> > > above operations with just one line of code to make the code easier to
> > > read and follow?
> > >
> > > Chrisso
> > >
> > >

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      12th Jun 2007
If:
Name: MyName
Refersto: Sheet1!$A$1:$B$2

then
Range("MYNAME").MergeArea

raises an error

Range("MYNAME")(1).MergeArea

doesn't.

--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote:

> Tom,
>
> What's the difference between
>
> Range("MYNAME")(1).MergeArea
>
> and
>
> Range("MYNAME").MergeArea
>
> Thanks,
> Barb
>
> "Tom Ogilvy" wrote:
>
> > I is unclear if the definition of myname is 1 cell or 2, but if it is
> > actually defined to be two cells or could be two cells, then I would alter it
> > as such:
> >
> >
> > Sub Test()
> >
> > With Range("MYNAME")(1).MergeArea
> > .ClearContents
> > .Locked = True
> > End With
> >
> > End Sub
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "Barb Reinhardt" wrote:
> >
> > > I'd probably do it this way
> > >
> > > Sub Test()
> > >
> > > With Range("MYNAME").MergeArea
> > > .ClearContents
> > > .Locked = True
> > > End With
> > >
> > > End Sub
> > >
> > > HTH,
> > > Barb Reinhardt
> > > "Chrisso" wrote:
> > >
> > > > I have a range name for a cell of MYNAME.
> > > >
> > > > MYNAME started off life just being a single cell and I could do all
> > > > sorts of wonderful things to it concisely:
> > > >
> > > > Range("MYNAME").ClearContents
> > > > Range("MYNAME").Locked = True
> > > >
> > > > I have now made MYNAME a merged cell that spans two columns (A1:B1).
> > > > Now I find for my code to work I have to select the merged cells first
> > > > then perform my operations:
> > > >
> > > > Range("MYNAME").Select
> > > > Selection.ClearContents
> > > > Selection.Locked = True
> > > >
> > > > Is there a way to deal with merged cells so that I can perform the
> > > > above operations with just one line of code to make the code easier to
> > > > read and follow?
> > > >
> > > > Chrisso
> > > >
> > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with pasting special merged cells to merged cells ritpg Microsoft Excel Programming 3 9th Mar 2010 07:14 PM
Copy paste non merged to merged cells jamalhakem@gmail.com Microsoft Excel Worksheet Functions 1 5th Feb 2009 05:25 PM
Autofit Merged cell Code is changing the format of my merged cells =?Utf-8?B?SkI=?= Microsoft Excel Misc 0 20th Aug 2007 02:12 PM
how do i link merged cells to a merged cell in another worksheet. =?Utf-8?B?aWJibQ==?= Microsoft Excel Worksheet Functions 3 27th Apr 2006 11:40 PM
Sorting merged cellsHow do I sort merged cells not identically siz =?Utf-8?B?TGF2YWw=?= Microsoft Excel Worksheet Functions 1 3rd Nov 2004 09:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 PM.