Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default myCell.Formula application unknown object error

I'm trying to use this macro but am having an application, unknown object
error:

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Formula & ",2)"
Next myCell
End Sub

Now when I try the above it gives me an application error.
But with the following code that you gave me it works great.

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Value & ",2)"
Next myCell
End Sub

why won't it work for a cell that is =1258/4569871 and keep the 1258/4569871
in the cell's formula of =Round(1258/4569871, 2) ???

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default myCell.Formula application unknown object error

mycell.formula starts with an = sign. Following seems to work
myCell.Formula = "=Round(" & Right(myCell.Formula, Len(myCell.Formula) - 1)
& ",2)"

"orangie" wrote:

I'm trying to use this macro but am having an application, unknown object
error:

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Formula & ",2)"
Next myCell
End Sub

Now when I try the above it gives me an application error.
But with the following code that you gave me it works great.

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Value & ",2)"
Next myCell
End Sub

why won't it work for a cell that is =1258/4569871 and keep the 1258/4569871
in the cell's formula of =Round(1258/4569871, 2) ???

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default myCell.Formula application unknown object error

THank you!!! :-)

"Gleam" wrote:

mycell.formula starts with an = sign. Following seems to work
myCell.Formula = "=Round(" & Right(myCell.Formula, Len(myCell.Formula) - 1)
& ",2)"

"orangie" wrote:

I'm trying to use this macro but am having an application, unknown object
error:

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Formula & ",2)"
Next myCell
End Sub

Now when I try the above it gives me an application error.
But with the following code that you gave me it works great.

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Value & ",2)"
Next myCell
End Sub

why won't it work for a cell that is =1258/4569871 and keep the 1258/4569871
in the cell's formula of =Round(1258/4569871, 2) ???

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default myCell.Formula application unknown object error

Using myCell.Formula brings along the "=" sign in the formula.

Try:

Public Sub Round_Made_Easy()
Dim myCell As Range
For Each myCell In Selection.Cells
With myCell
If Not IsEmpty(.Value) Then _
myCell.Formula = "=ROUND(" & _
Mid(.Formula, 1 - .HasFormula) & ",2)"
End With
Next myCell
End Sub



In article ,
orangie wrote:

I'm trying to use this macro but am having an application, unknown object
error:

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Formula & ",2)"
Next myCell
End Sub

Now when I try the above it gives me an application error.
But with the following code that you gave me it works great.

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Value & ",2)"
Next myCell
End Sub

why won't it work for a cell that is =1258/4569871 and keep the 1258/4569871
in the cell's formula of =Round(1258/4569871, 2) ???

Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default myCell.Formula application unknown object error

What's wrong with keeping to your original thread in the other news group?

Wastes a lot of time and effort giving the same answers in more than one group.


Gord Dibben MS Excel MVP

On Wed, 21 Mar 2007 12:53:10 -0700, orangie
wrote:

I'm trying to use this macro but am having an application, unknown object
error:

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Formula & ",2)"
Next myCell
End Sub

Now when I try the above it gives me an application error.
But with the following code that you gave me it works great.

Option Explicit
Sub round_made_easy()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.Formula = "=Round(" & myCell.Value & ",2)"
Next myCell
End Sub

why won't it work for a cell that is =1258/4569871 and keep the 1258/4569871
in the cell's formula of =Round(1258/4569871, 2) ???

Thanks!




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
Error 1004: Application or Object Defined Error BEEJAY Excel Programming 0 September 18th 06 07:59 PM
Error 1004, Application-definded or object-defined error Mirco Wilhelm[_2_] Excel Programming 9 January 7th 06 04:56 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 10:19 AM.

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"