PC Review


Reply
Thread Tools Rate Thread

Create Macro to copy a formula to range of cell

 
 
=?Utf-8?B?c3VtbWVy?=
Guest
Posts: n/a
 
      14th Jun 2007
Excel 2000. I am a novice to this and intend to create a macro to copy a
fixed formula to a range of cell by a click of a button.

Below is the marco created but was prompted with error message when I run it.

Error message reads "Run-time error "5" : Invalid procedure cell or
argument" on the row starting with "Application.WorksheetFunction.IF....".
Please help.

Sub Macro2()
'Public strModule As String
' Macro2 Macro

Dim IsNumber As Variant
Dim Search As Variant

Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A10").Select
Application.WorksheetFunction.IF(IsNumber(Search("TOTAL", C16)),
(Right(Left(C16, Len(C16) - 1), 5)), "").Paste

Range("A10").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=200
Range("A10:A200").Select
ActiveSheet.Paste
End Sub


 
Reply With Quote
 
 
 
 
AD108
Guest
Posts: n/a
 
      14th Jun 2007
Hi,

No sure exactly what you need to do from your code, but see the part I
replaced. You don't want to use the "application.worlsheetfunction" method.
That is for when you want to use an excel function to manipulate a value in
your code.

Hopefully this will get you on the right track.

Sub Macro2()
'Public strModule As String
' Macro2 Macro

Dim IsNumber As Variant
Dim Search As Variant

Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A10").Select


ActiveCell.FormulaR1C1 = _
"=IF(ISNUMBER(SEARCH(""TOTAL"", R[11]C[-1])),(RIGHT(LEFT(R[11]C[-1],
LEN(R[11]C[-1]) - 1), 5)), """")"


Range("A10").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=200
Range("A10:A200").Select
ActiveSheet.Paste
End Sub

"summer" <(E-Mail Removed)> wrote in message
news:5DE8593B-4E99-4F61-ACF7-(E-Mail Removed)...
> Excel 2000. I am a novice to this and intend to create a macro to copy a
> fixed formula to a range of cell by a click of a button.
>
> Below is the marco created but was prompted with error message when I run
> it.
>
> Error message reads "Run-time error "5" : Invalid procedure cell or
> argument" on the row starting with "Application.WorksheetFunction.IF....".
> Please help.
>
> Sub Macro2()
> 'Public strModule As String
> ' Macro2 Macro
>
> Dim IsNumber As Variant
> Dim Search As Variant
>
> Columns("A:A").Select
> Selection.Insert Shift:=xlToRight
> Range("A10").Select
> Application.WorksheetFunction.IF(IsNumber(Search("TOTAL", C16)),
> (Right(Left(C16, Len(C16) - 1), 5)), "").Paste
>
> Range("A10").Select
> Selection.Copy
> ActiveWindow.SmallScroll Down:=200
> Range("A10:A200").Select
> ActiveSheet.Paste
> End Sub
>
>



 
Reply With Quote
 
=?Utf-8?B?c3VtbWVy?=
Guest
Posts: n/a
 
      15th Jun 2007
I wasn't specific.
Actually needs to copy a "If" formula to the cell when the formula search
and found the word "Total" in column C
I have tried your advise but couldn't get the formula pasted on the cell.
Your help again please.

"AD108" wrote:

> Hi,
>
> No sure exactly what you need to do from your code, but see the part I
> replaced. You don't want to use the "application.worlsheetfunction" method.
> That is for when you want to use an excel function to manipulate a value in
> your code.
>
> Hopefully this will get you on the right track.
>
> Sub Macro2()
> 'Public strModule As String
> ' Macro2 Macro
>
> Dim IsNumber As Variant
> Dim Search As Variant
>
> Columns("A:A").Select
> Selection.Insert Shift:=xlToRight
> Range("A10").Select
>
>
> ActiveCell.FormulaR1C1 = _
> "=IF(ISNUMBER(SEARCH(""TOTAL"", R[11]C[-1])),(RIGHT(LEFT(R[11]C[-1],
> LEN(R[11]C[-1]) - 1), 5)), """")"
>
>
> Range("A10").Select
> Selection.Copy
> ActiveWindow.SmallScroll Down:=200
> Range("A10:A200").Select
> ActiveSheet.Paste
> End Sub
>
> "summer" <(E-Mail Removed)> wrote in message
> news:5DE8593B-4E99-4F61-ACF7-(E-Mail Removed)...
> > Excel 2000. I am a novice to this and intend to create a macro to copy a
> > fixed formula to a range of cell by a click of a button.
> >
> > Below is the marco created but was prompted with error message when I run
> > it.
> >
> > Error message reads "Run-time error "5" : Invalid procedure cell or
> > argument" on the row starting with "Application.WorksheetFunction.IF....".
> > Please help.
> >
> > Sub Macro2()
> > 'Public strModule As String
> > ' Macro2 Macro
> >
> > Dim IsNumber As Variant
> > Dim Search As Variant
> >
> > Columns("A:A").Select
> > Selection.Insert Shift:=xlToRight
> > Range("A10").Select
> > Application.WorksheetFunction.IF(IsNumber(Search("TOTAL", C16)),
> > (Right(Left(C16, Len(C16) - 1), 5)), "").Paste
> >
> > Range("A10").Select
> > Selection.Copy
> > ActiveWindow.SmallScroll Down:=200
> > Range("A10:A200").Select
> > ActiveSheet.Paste
> > End Sub
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a macro to move one cell to the right w/o specifying range P Schneider Microsoft Excel Programming 2 11th Nov 2008 09:05 PM
Macro to copy a cell contains formula to a range Frank Situmorang Microsoft Excel Programming 2 4th Jun 2008 10:16 AM
Macro to copy a certain a cell to a dynamic range Frank Situmorang Microsoft Excel Programming 5 14th Mar 2008 04:26 AM
create formula to compare cell 1 with a range of cell =?Utf-8?B?S0tYQw==?= Microsoft Excel Programming 2 7th Jan 2006 06:37 AM
How to copy formula from one cell to a range? Jason Weiss Microsoft Excel Programming 1 22nd Apr 2005 03:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:28 AM.