Solved

Replace Formula

Posted on 2014-01-21
8
170 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now