Solved

Replace Formula

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

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 80

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 80

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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 how to use a scrolling table in Microsoft Excel using the INDEX function.

706 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

17 Experts available now in Live!

Get 1:1 Help Now