Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
prizm1
 
Posts: n/a
Default Clearing the Contents of Merged Cells

How would I implement VBA to clear the contents of a range that contains
merged cells? The following code results in a runtime error '1004' :
"Cannot change part of a merged cell."

************************************************** ***

If Union(ActiveCell, Range("ProbArea")).Address =
Range("ProbArea").Address Then

Ans = MsgBox("Do you want to CLEAR the contents of CURRENTLY
SELECTED CELL'S ROW?", vbYesNo)

If Ans = vbNo Then
Exit Sub
End If

If Ans = vbYes Then

Application.ScreenUpdating = False

ActiveCell.EntireRow.Select
Selection.Cells(1, 1).Select
ActiveCell.Offset(0, 0).ClearContents
ActiveCell.Offset(0, 1).ClearContents
ActiveCell.Offset(0, 2).ClearContents
ActiveCell.Offset(0, 3).ClearContents
ActiveCell.Offset(0, 4).ClearContents
ActiveCell.Offset(0, 5).ClearContents
ActiveCell.Offset(0, 6).ClearContents

Application.ScreenUpdating = True

End If

*********************************************

Offset (0, 1), (0, 2), (0, 3) and (0, 4) are merged cells.

  #2   Report Post  
Jim Cone
 
Posts: n/a
Default

p,
'---------------------
Dim Ans As Long
If Union(ActiveCell, Range("ProbArea")).Address = Range("ProbArea").Address Then

Ans = MsgBox("Do you want to CLEAR the contents of CURRENTLY Selected CELL 'S ROW?", vbYesNo)

If Ans = vbNo Then
Exit Sub
Else
Application.ScreenUpdating = False
With ActiveCell.EntireRow
.UnMerge
.ClearContents
End With
Application.ScreenUpdating = True
End If
End If
'----------------------
Jim Cone
San Francisco, USA



"prizm1"
wrote in message

How would I implement VBA to clear the contents of a range that contains
merged cells? The following code results in a runtime error '1004' :
"Cannot change part of a merged cell."
************************************************** ***
If Union(ActiveCell, Range("ProbArea")).Address =
Range("ProbArea").Address Then

Ans = MsgBox("Do you want to CLEAR the contents of CURRENTLY
SELECTED CELL'S ROW?", vbYesNo)
If Ans = vbNo Then
Exit Sub
End If
If Ans = vbYes Then
Application.ScreenUpdating = False
ActiveCell.EntireRow.Select
Selection.Cells(1, 1).Select
ActiveCell.Offset(0, 0).ClearContents
ActiveCell.Offset(0, 1).ClearContents
ActiveCell.Offset(0, 2).ClearContents
ActiveCell.Offset(0, 3).ClearContents
ActiveCell.Offset(0, 4).ClearContents
ActiveCell.Offset(0, 5).ClearContents
ActiveCell.Offset(0, 6).ClearContents
Application.ScreenUpdating = True
End If
*********************************************

Offset (0, 1), (0, 2), (0, 3) and (0, 4) are merged cells.

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

Activecell.value = ""
(drop the .clearcontents version)
will work.

As will:
activecell.mergarea.clearcontents

(add in your .offset() stuff)



prizm1 wrote:

How would I implement VBA to clear the contents of a range that contains
merged cells? The following code results in a runtime error '1004' :
"Cannot change part of a merged cell."

************************************************** ***

If Union(ActiveCell, Range("ProbArea")).Address =
Range("ProbArea").Address Then

Ans = MsgBox("Do you want to CLEAR the contents of CURRENTLY
SELECTED CELL'S ROW?", vbYesNo)

If Ans = vbNo Then
Exit Sub
End If

If Ans = vbYes Then

Application.ScreenUpdating = False

ActiveCell.EntireRow.Select
Selection.Cells(1, 1).Select
ActiveCell.Offset(0, 0).ClearContents
ActiveCell.Offset(0, 1).ClearContents
ActiveCell.Offset(0, 2).ClearContents
ActiveCell.Offset(0, 3).ClearContents
ActiveCell.Offset(0, 4).ClearContents
ActiveCell.Offset(0, 5).ClearContents
ActiveCell.Offset(0, 6).ClearContents

Application.ScreenUpdating = True

End If

*********************************************

Offset (0, 1), (0, 2), (0, 3) and (0, 4) are merged cells.


--

Dave Peterson
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
con't paste merged cells Oldjay Excel Worksheet Functions 3 June 16th 05 11:40 PM
Merged Cells TerryTutor Excel Discussion (Misc queries) 1 June 14th 05 05:17 AM
how do populate empty cells with the contents of populated cells . Jim99 Excel Discussion (Misc queries) 6 April 21st 05 05:44 PM
paste info into merged cells Marc Setting up and Configuration of Excel 0 December 6th 04 09:09 PM
How do I "Wrap Text" & "Autofit" within Merged Cells in Excel? 6-shooter Excel Worksheet Functions 3 October 31st 04 12:14 AM


All times are GMT +1. The time now is 08:42 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"