Solved

Replace Formula

Posted on 2014-01-21
8
184 Views
Last Modified: 2014-01-22
How can I replace  "=RC[-10]*RC[-5]"
with  

 "=IFERROR(VLOOKUP(TODAY(),Holidays!B$2:D$9,3,0),1)*E13*J13"



>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 Range("O10").FormulaR1C1 = "Day's Total Earned Inc"
        Range("O11:O" & row - 1).FormulaR1C1 = "=RC[-10]*RC[-5]"
        Range("O11:O" & row - 1).Style = "Comma"  


 "=IFERROR(VLOOKUP(TODAY(),Holidays!B$2:D$9,3,0),1)*E13*J13"
0
Comment
Question by:leezac
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 39798937
Range("O10").FormulaR1C1 = "Day's Total Earned Inc"
        Range("O11:O" & row - 1).FormulaR1C1 = "=IFERROR(VLOOKUP(TODAY(),Holidays!B$2:D$9,3,0),1)*E13*J13"
        Range("O11:O" & row - 1).Style = "Comma"   

Open in new window



Is this what you are wanting? Or how are you trying to replace it?
0
 

Author Comment

by:leezac
ID: 39798951
That is what I was thinking, but the old formula uses  "=RC[-10]*RC[-5]"


I need  "=IFERROR(VLOOKUP(TODAY(),Holidays!B$2:D$9,3,0),1)*E13*J13"
to be entered starting at O11

The formula works if I add to a cell manually.  But the former code enters it using vba using just
"=RC[-10]*RC[-5]"
but I needed to modify it thus the new formula but not sure how to add it.  Why I am posting.
0
 
LVL 81

Expert Comment

by:byundt
ID: 39799107
Try:
Range("O11:O" & row - 1).FormulaR1C1 = "=IFERROR(VLOOKUP(TODAY(),Holidays!R2C[-13]:R9C[-11],3,0),1)*R[2]C[-10]*R[2]C[-5]"

Open in new window


Note that the formula in O11 will be looking at values in E13 and J13 (i.e. two rows lower).
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:leezac
ID: 39800052
That did not work - I am attaching a sample file.  I need to use If Active sheet.name etc.

I need the formula to copy down column starting at O11.


The formula checks for Todays date on the Holiday Table

Thanks
ee---workdays-multipliers--2-.zip
0
 
LVL 81

Expert Comment

by:byundt
ID: 39800154
You need to define a value for the variable Row in your macro.

Also, ActiveSheet is a VBA keyword that points to the worksheet that is currently active. You don't need to Dim it.

The code snippet below fixes both problems and illustrates how to put the formulas in column O two ways: one using R1C1 notation as requested, and another using A1 notation that you may find easier to understand.
Sub Enterformula()
Dim Row As Long
Row = 15
If Activesheet.Name = "Variance Check" Then
        Range("O10").FormulaR1C1 = "Day's Total Earned Inc"
        
        'Set formulas in column O using R1C1 notation
        Range("O11:O" & Row - 1).FormulaR1C1 = "=IFERROR(VLOOKUP(TODAY(),Holidays!R2C[-13]:R9C[-11],3,0),1)*R[2]C[-10]*R[2]C[-5]"
        
        'Set formulas in column O using A1 notation
        Range("O11:O" & Row - 1).Formula = "=IFERROR(VLOOKUP(TODAY(),Holidays!B$2:D$9,3,0),1)*E13*J13"
        
        Range("O11:O" & Row - 1).Style = "Comma"
    End If

End Sub

Open in new window

0
 

Author Comment

by:leezac
ID: 39800258
Thank you - Iam working on adding the above

I also need if I use this formula then if there is no match to Today's date then  it still multiplies  E13*J13.

Range("O11:O" & row - 1).Formula = "=IFERROR(VLOOKUP(TODAY(),Holidays!B$2:D$9,3,0),1)*E11*J11"
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39800282
When you set the .Formula property, make sure that the formula text is appropriate for the first cell in the range (O11). Excel VBA will handle the relative and absolute addressing bits for the other cells in the range.

Should the formula for row 11 be using E13*J13 or E11*J11? Your most recent Comment talks about both.

The IFERROR will return either a value from column D in Holidays worksheet or 1. So either way you get something to multiply by the product of column E and J.
0
 

Author Comment

by:leezac
ID: 39800322
It should be E11*J11
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question