Converting a Formula to VBA - vba

I have two Sheets , Sheet1 and Sheet2. The column J in sheet1 contains, the Name of Project. I wanted the closing date of poject from sheet2. for this,
I am looking into sheet2 with Project Name of sheet1 and if they are same, then I copy the date to sheet1 in column w.
once, I have copied, then i compare the date in column u with the column w and say if it is ok or not ok.
I have formulated the above conditions in the form of formula.
But I wanted to have them in VBA. Could anyone suggest how i can Frame my formula in VBA.
Column W =IFERROR(VLOOKUP(J2;Sheet2!$A:$L;7;0);"")
Column X=IF($W2>$U2;0;1)
Column Y=IF($W2<=$U2;0;1)
I would not prefer to use recorded macros.

The easiest way is to record macro, when you activate and accept formula. The in VBA code I can find the right solutions.
For example:
IF($W2>$U2;0;1) for cell H3
Range("H3").Select
ActiveCell.FormulaR1C1 = "=IF(RC23>RC21,0,1)"

Range("H3").Formula = "=IF(RC23>RC21,0,1)"

Related

Google spreadsheet Conditional Formatting rows depending on dates on current and another sheet

So I have Sheet1 and Sheet2 (in one spreadsheet) where:
Sheet1 contains data from A:E
Sheet2 contains data from A:K
I need to lookup the Sheet1 B cells text in Sheet2 A cells and return Sheet2 J column value (which contains dates) and if Sheet2 date < TODAY then conditional formatting should apply.
I used this formula for conditional formatting:
VLOOKUP($B:$B,Sheet2!$A:$K,10,0)<TODAY()
This works well if I want to use it just to show the values but conditonal formatting are not applying to cells
Update:
I tried it with a simpler function. I have added the dates to the F column and used the following conditional formatting formula:
F:F<TODAY()
Still doesn't work.
PS: I made sure the formats are set to DATE where DATEs are present.
Try INDIRECT function according to advanced conditional formatting description:
Note: Formulas can only reference the same sheet, using standard
notation "(='sheetname'!cell)." To reference another sheet in the
formula, use the INDIRECT function.

VBA: Highlight a row with a specific column value

I am working on a very large excel 2010 workbook with several sheets.
One of the sheets is called "RatePlan" and one of the columns in this sheet is "RatePlanCde".
Some of these "RatePlanCde" (a total of 2514) are not valid anymore and have been highlighted in Red.
I need to find if "RatePlanCde" column exists in any other sheets. If so, then highlight the row with the invalid "RatePlanCde" value in all the sheets in Red too.
Can this be done using a VBA script and how?
Formula for conditional formatting is a simple VLookup
The following formula assumes that the codes in the "other" sheets is in Col A, the codes are in the Rateplan-Sheet in Col C and the "INVALID"-marker in COl D:
=VLOOKUP(A2;RatePlan!$C$2:$D2515;2;FALSE)="INVALID"

Highlight a cell if its copied to another sheet

I have a formula that will copy values from one column on Sheet B to another column on another Sheet A. What I'd like to do is highlight the cells that were copied on Sheet B and highlight the cells in Sheet A that are not on Sheet B, essentially the inverse of the first part. On Sheet B only columns G and H would be highlighted but Sheet A could be from column A to H.
=IFERROR(INDEX(Sheet2!G$3:G$7,MATCH(1,INDEX((Sheet2!$D$3:$D$7=$A3)*(Sheet2!$B$3:‌​$B$7=$C3),),0)),G3)
You could set up conditional formatting with the same logic to change the colour or either the cell that you are setting or the one that you are copying from.
Beware: this kind of code can make your spreadsheet very slow if over used.
So in one range (sheet 2) , you would have conditional formatting set up to highlight the cell if
this match failed
MATCH(1,INDEX((Sheet2!$D$3:$D$7=$A3)*(Sheet2!$B$3:‌​$B$7=$C3),),0)
In the other range (sheet 1 a:h)
you would highlight if ISERROR(INDEX(Sheet2!G$3:G$7,MATCH(1,INDEX((Sheet2!$D$3:$D$7=$A3)*(Sheet2!$B$3:‌​$B$7=$C3),),0)))
has picked the value from sheet2
I may have incorrectly butchered your code, but you should get the idea. Where you currently have a range of values, select the range, insert the conditional formatting, but edit the range to only check the first cell, it will automatically increment for you (if you remove the appropriate $ signs)
conditional formatting intro

Search column in one Excel workbook to paste Adjacent Cell's Value into active VBA script

I have Workbook1 and Workbook2 and need to search column A in Workbook1 for specific string value and then copy adjacent cell that is in column B of Workbook1 to the macro being run where I need to insert the value in the following formula in VBA script: =(ROUNDUP((F2+40)/[VALUE],0))*[VALUE]. The [VALUE] = the value taken from the adjacent cell in column B from Workbook1. Workbook2 is where the macro is running on.
I am being rushed at the moment and if this is not clear enough. I will come back and clarify as needed.
VALUE = WorksheetFunction.VLookup(theString, Workbooks("Workbook1").Worksheets("Sheet1").Range("A:B"), 2)

Moving Data between Worksheets based on a key

In both worksheets I have a key in column A. Not all of the key values are in both worksheets.
For each key value in column A of Worksheet 1, I want to find the corresponding key in worksheet 2 and move the data in column B of worksheet 2 into column B of worksheet 1.
I have never programmed a macro so I am completely lost for writing this code.
There is no need for VBA here, Philip.
Try this formula in cell B1 of Sheet1:
=IFERROR(vlookup(A1,Sheet2!A:B,2,false),"")
If you are on XL 2003, then do this:
=IF(ISERROR(vlookup(A1,Sheet2!A:B,2,false)),"",vlookup(A1,Sheet2!A:B,2,false))
Then drag this formula down for the rest of your data in Column A of Sheet1.
NB - Sheet2 is the assumed name of your Worksheet2, you may need to change to fit your needs.
NB2 - you can lookup vlookup in Excel Help (or online) to better understand what it does
Are you sure you need to use a macro for this? It sounds to me like you are using Excel and a simple VLOOKUP formula would do what you need.
A VLOOKUP looks like this: =VLOOKUP(A1,Sheet2!$A:$B,2,FALSE)
Where A1 is your reference cell (in this case you "key" in column A).
Sheet2!$A:$B is the lookup table (in this case columns A and B from the second sheet).
2 is the column number that you want data from, counting from the left (in this case the second column, column B)
FALSE tells the formula to only return values for exact matches. TRUE returns the closest match in the lookup table.