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"
Related
I am having an issue in Excel dragging to fill in formulas. I have formulas in rows such that each row has a different formula which reference to rows/cells on other sheets.
Let's say on Sheet 1, the formulas in the cells C2:C9 pulls data from Sheet 2 from cells C4, G4, H4, etc. If I highlight Sheet 1 cells C2:C9 and then click to drag down to form another group of formulas in cells C10:C17, the formulas inside change their reference by 8 rows such that if Sheet 1 C2 pulls data from Sheet 2 G4, the next similar formula in Sheet 1 C10 ends up pulling data from Sheet 2 G12.
This is the problem I am having; instead of the formulas changing to reference every 8 rows, how could I make it so that it only changes by 1 row instead? Or, for every new group of formulas dragged and filled, change the references in those formulas only by 1 row. If there is still confusion, consider if the cells C2:C9 were merged as a single cell. Even if you dragged that formula down, the formula inside would still change by 8 rows despite only forming 1 cell each time.
As far as I am aware, there is no built-in Excel function to do this and I believe the only way to do this would be some VBA code, but I am unfamiliar with VBA language. Since this would be a one time thing, the VBA code could either apply this 'row formatting' as I click and drag, or the VBA code could just automatically fill in the cells for me.
Use INDEX() and some math:
In C2 it would be something like:
=INDEX(Sheet2!C:C,(ROW(1:1)-1)/8+4)
Where 8 is the spacing of the formula and 4 is the first row desired to return.
C2 would return Sheet2!C4, C10 would be Sheet2!C5
Using this you can modify the other formulas to return the desired pattern.
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)"
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
I'm trying to compare two Excel sheets, Sheet1 column O to Sheet2 column A:M, if it found a match, it will copy Sheet 2 "down cell of matched data" (ie match data A3, copy A4) then paste to Sheet 1 column R. I'm (very) new to VBA and Macros so I don't know how to do this. Thanks in advance!
In sheet 1 of column O - datas are USD,JPY,TWD, etc. In sheet 2 column A to M, a specified exchange rate per currency. If sheet 1 column O data is USD, it will search in Sheet 2 with matching "USD"; if cell A3's data is USD, the exchange rate is in cell A4 which will be copied and pasted into column R of Sheet 1 corresponding to the row of USD.
So what I'm dealing with is something kind of like this:
This is what I’m looking for after the macro
Since Sheet 1’s cell O1 matches Sheet 2’s cell A3, I want it to return Sheet 2’s cell A4’ s value and paste it to corresponding row of Sheet 1’s cell R1.
Let me know if this makes sense or if you need further clarification.
Thanks!
Most of the code you need you can manage by yourself using macro recorder:
Start recording new macro
Select cell O1
Copy selected cell (by pressing RMB or ctrl+C)
Go to Sheet2
Select your data (A3:M7) with mouse
Press ctrl+F to open "Find" window
Paste value of copied cell
Press Enter. Cell with searched value should be selected
Press down arrow to move selection one cell down
Copy value from selected cell
Go to Sheet1
Press right arrow to move to column R
Paste copied value
Stop recording the macro
After that you need to find how to use For loops and add it to your code. Good luck!
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.