?
Solved

Replace Formula

Posted on 2014-01-21
8
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

770 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