Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Run Time Error 1004

I have the following code ina worksheet that wraps text in merged cells. I
also have some links from one cell to another to avoid entering text twice.
When I protect the sheet and try to enter text into the cell, I get the Run
Time error message 1004. I get an option to end or debug. If I debug, it
takes to the line in the code:

ma.MergeCells = False

I can click on End and then everything is OK. How do I modify the code so I
don't get the error please?

Thanks,

Gary

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range

With Target
If .MergeCells And .WrapText Then
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
Application.ScreenUpdating = True
End If
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Run Time Error 1004

I don't know what's up with .MergeCells=False, it worked fine in a simple
test I just ran.

OT: Instead of this:

For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next


why not use MrgeWdth = ma.Width?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"gwinder" wrote in message
...
I have the following code ina worksheet that wraps text in merged cells. I
also have some links from one cell to another to avoid entering text
twice.
When I protect the sheet and try to enter text into the cell, I get the
Run
Time error message 1004. I get an option to end or debug. If I debug, it
takes to the line in the code:

ma.MergeCells = False

I can click on End and then everything is OK. How do I modify the code so
I
don't get the error please?

Thanks,

Gary

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range

With Target
If .MergeCells And .WrapText Then
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
Application.ScreenUpdating = True
End If
End With
End Sub



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
Run Time Error 1004: Application or Object Defined Error BEEJAY Excel Programming 4 October 18th 06 04:19 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Run time error '1004': Generaol ODBC error Dwaine Horton[_3_] Excel Programming 2 April 26th 05 02:52 PM
Run time error 1004 General ODCB Error Kevin Excel Programming 3 February 26th 05 12:51 PM


All times are GMT +1. The time now is 12:45 AM.

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

About Us

"It's about Microsoft Excel"