Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Dealing with merged cells

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Dealing with merged cells

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Dealing with merged cells

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Dealing with merged cells

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Dealing with merged cells

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy paste non merged to merged cells [email protected] Excel Worksheet Functions 1 February 5th 09 05:25 PM
How can I sort an Excel Doc containing merged & non-merged cells? KellyH Excel Discussion (Misc queries) 11 June 10th 08 04:12 AM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
how do i link merged cells to a merged cell in another worksheet. ibbm Excel Worksheet Functions 3 April 27th 06 11:40 PM
Sorting merged cellsHow do I sort merged cells not identically siz Laval Excel Worksheet Functions 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 11:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"