#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro problem

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default Macro problem

uI didn't test it, but _ (underline) character in line

If Cel.HasFormula Then _

is a wrong syntax, try your macro without it:
If Cel.HasFormula Then

Regards,
Stefi

€ť ezt Ă*rta:

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default Macro problem

Either that, or remove the End If after.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Stefi" wrote in message
...
uI didn't test it, but _ (underline) character in line

If Cel.HasFormula Then _

is a wrong syntax, try your macro without it:
If Cel.HasFormula Then

Regards,
Stefi

" ezt írta:

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro problem

Thanks for the replies. I've tried both modifications, but still get
the error:
"Application-defined or object-defined error" (for the same line)
So the macro (now) looks like this:

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"

For Each Cel In Selection
If Cel.HasFormula Then
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next
End Sub

any ideas?
Thanks

-John
-=====================
Stefi wrote:
uI didn't test it, but _ (underline) character in line

If Cel.HasFormula Then _

is a wrong syntax, try your macro without it:
If Cel.HasFormula Then

Regards,
Stefi

" ezt írta:

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Macro problem

One problem at least is that the formulas selected have "=" in front of
them. So to remove them:


Cel.Formula = Prefix & Mid(Cel.Formula, 2) & Sufix

This assumes that Mid(Cel.Formula, 2) returns a legitimate cell reference.

--
Jim
wrote in message
oups.com...
Thanks for the replies. I've tried both modifications, but still get
the error:
"Application-defined or object-defined error" (for the same line)
So the macro (now) looks like this:

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"

For Each Cel In Selection
If Cel.HasFormula Then
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next
End Sub

any ideas?
Thanks

-John
-=====================
Stefi wrote:
uI didn't test it, but _ (underline) character in line

If Cel.HasFormula Then _

is a wrong syntax, try your macro without it:
If Cel.HasFormula Then

Regards,
Stefi

" ezt írta:

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro problem

THANK YOU (both of you)!!!!!!!!!!!!!!!!!!!
That did it. Nothing like saving a TON of manual editing. :)
Thanks again.

-John
-----------------------
Jim Rech wrote:
One problem at least is that the formulas selected have "=" in front of
them. So to remove them:


Cel.Formula = Prefix & Mid(Cel.Formula, 2) & Sufix

This assumes that Mid(Cel.Formula, 2) returns a legitimate cell reference.

--
Jim
wrote in message
oups.com...
Thanks for the replies. I've tried both modifications, but still get
the error:
"Application-defined or object-defined error" (for the same line)
So the macro (now) looks like this:

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"

For Each Cel In Selection
If Cel.HasFormula Then
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next
End Sub

any ideas?
Thanks

-John
-=====================
Stefi wrote:
uI didn't test it, but _ (underline) character in line

If Cel.HasFormula Then _

is a wrong syntax, try your macro without it:
If Cel.HasFormula Then

Regards,
Stefi

" ezt írta:

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro problem

Cel.formula will include the leading equal sign.

Maybe...

Cel.Formula = Prefix & mid(Cel.Formula,2) & Sufix



wrote:

Thanks for the replies. I've tried both modifications, but still get
the error:
"Application-defined or object-defined error" (for the same line)
So the macro (now) looks like this:

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"

For Each Cel In Selection
If Cel.HasFormula Then
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next
End Sub

any ideas?
Thanks

-John
-=====================
Stefi wrote:
uI didn't test it, but _ (underline) character in line

If Cel.HasFormula Then _

is a wrong syntax, try your macro without it:
If Cel.HasFormula Then

Regards,
Stefi

" ezt írta:

(Excel 2003) Can anyone help with a quick macro I have that is giving
me an error?
The purpose of the macro is to find all formulas on a page (range) and
increment the Column by 1. The error is on the line "cel.formula =
prefix & cel.formula & sufix"

The formulas I am changing are all references to another worksheet. Is
the problem that the formula contains an equal sign in it?

Any help is GREATLY appreciated!
Thanks
-John
--------------------------------------------------------------------------------

Sub EditFormula()
Dim Cel As Range
Dim Sufix As String

Dim Prefix As String
Prefix = "=Offset("
Sufix = ", 0, 1)"
For Each Cel In Selection
If Cel.HasFormula Then _
Cel.Formula = Prefix & Cel.Formula & Sufix
End If
Next Cel
End Sub



--

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
Autofit with Merged Cells/Wrap Text Macro Problem elfmajesty Excel Discussion (Misc queries) 3 May 25th 06 06:32 PM
Problem with Before_Save Macro Jay Excel Discussion (Misc queries) 5 May 18th 06 06:47 PM
deleting a macro resulted in a problem militant Excel Discussion (Misc queries) 0 April 26th 05 05:21 AM
Circular Problem needs Macro NICK Excel Discussion (Misc queries) 2 February 1st 05 09:09 AM
Problem executing a macro from different workbook where it is Sergio Calleja Excel Discussion (Misc queries) 1 January 17th 05 12:38 PM


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