Changing Formula sheet reference with Macro - vba

Hello everyone i'm new to this site! i wanted to see if anyone could assist with a concept i believe is possible but don't know how to achieve it.
Essentially i have a formula that has Vlookups and references other sheets, this formula is the same but the sheet referenced changes for each column as each column references a different sheet. this is going to be done 135 times over 8 times.
=IF((IFERROR(VLOOKUP(D3,'[2015_Big_Book_Communication_10_19_15.xlsx]**Credit P-1**'!$C$2:$O$5000,9,FALSE),"Not Scheduled"))=0,1,IFERROR(VLOOKUP(D3,'[2015_Big_Book_Communication_10_19_15.xlsx]**Credit P-1**'!$C$2:$O$5000,9,FALSE),"Not Scheduled"))
I want to use a macro to change the bolded sheet reference based upon a cell.
my idea is to have all the sheet names listed in a column and have the macro edit the equation for each row and then just paste the formulas transposed.
Is this possible?

Use the following formula:
=IF((IFERROR(VLOOKUP(D3,INDIRECT("'[2015_Big_Book_Communication_10_19_15.xlsx]"&H3&"'!$C$2:$O$5000"),9,FALSE),"Not Scheduled"))=0,1,IFERROR(VLOOKUP(D3,INDIRECT("'[2015_Big_Book_Communication_10_19_15.xlsx]"&H3&"'!$C$2:$O$5000"),9,FALSE),"Not Scheduled"))
In a column ("col H" in this example) write the sheet names and use indirect formula to refer to those names.

Related

Conditional formatting 1 cell based on cell input on another sheet, apply to entire row

For work I need to create a resource management excel file. My goal is to create an overview as is seen here:
If John would have taken a few hours off, or if he has a fey hours of sick leave, I would like to turn this cell only to change colour so I know that John will be absent for whatever reason on this day.
However, since I'm creating this for an entire row (for a whole year), I do not want to create conditional formatting per cell because that would be plain madness.
Here is an example per employee (in this example John):
enter image description here
So what I need is a formula to check if a cell in a row (for example sick leave) on the employee worksheet is grater than 0 and then change the colour of only the corresponding cell on the recourse planning worksheet, not the entire row.
Does any of you guys know if this is possible in excel 2016? Preferably without VBA scripting since I have to transfer this excel file to a co-worker who is not into VBA programming.
Thank in advance.
Nuntius transmittendus!
This is definitely possible without any code. Use CountIf() as tinus087 commented. The tricky part is how to create the address range used by the CountIf() so that you can put one conditional format on all the cells. On the the one hand you need the column of the cells being checked to match the column of your total cell. On the other hand the worksheet tab name needs to change depending on which row you are on. So use INDIRECT() to point to the correct worksheet and OFFSET() to look at the correct cells.
So, for cell C4, the formula you want to use as the range in your CountIf() is OFFSET(INDIRECT($A4&"!A1"),3,COLUMN(C1)-1,4). When applied to cell C4 this creates address John!C4:C7. When used for cell D4, it results in John!D4:D7.
You'll probably want some error checking to deal with the #REF! error happens when the formula is applied to a row without a first name or where the name listed doesn't match any worksheet tabs.
Something else to think about, if you haven't already, what happens if there are two John's? Is the 2nd John going to be named John2?

Excel - Can not compare two spreadsheets

I have gone through V-look-up guides online but I can not find one that explains what I am looking for. I am trying to avoid manual checking.
What I have:
Two sheets, Sheet 1 and Sheet 2. Both sheets have the same column names (A1:G1) with multiple rows.
Sheet 1 contains my spreadsheet where I update daily. Sheet 2 is the same spreadsheet that is imported from a application (but has hourly updates). Data can change in each row (for some columns) along with additional added/deleted rows. The data is text, dates and numbers (mixture of both too).
I want to run a formula to highlight the changes on sheet 1 (grabbing the updates from sheet 2. Once I find out the formula works correctly, I would like to know how to replace the Sheet 2 updates onto my spreadsheet (Sheet 1).
I am looking for a formula outside of creating a macro (worst case scenario).
Currently I have the following vlook up formula:
=VLOOKUP(A1,sheet2!$A:$A,1,FALSE)
When I run this in another column (lets say in H1 in Sheet 1), it will display "N/A" if that column (A1) in Sheet 2 is not the same. If it is the same, it will write out the column name.
When I use the following formula highlighting all the cells in Sheet 1, I get a values error:
=VLOOKUP(A1:G33,Sheet2!$A:$G,1,FALSE)
How could I apply that formula to the whole spreadsheet (I guess it would apply to both sheets) and have it highlight records in my spreadsheet (Sheet1). Could it also highlight rows that are missing or added?
The data in Column 1 and 2 would never change (they are ticket numbers). Only change that can apply is if ticket is closed, so when I import the updated spreadsheet that row isn't there anymore. If you think there might be a better way to tackle this down, I would like to hear.
Please let me know if I am not clear.
Here are some example screenshots:
Just in case, the formula for the totals are (adjusting the columns for each):
=SUBTOTAL(3,INDEX(C:C,2):INDEX(C:C,ROW()-1))
Sheet 2 is setup very similar. When I import it into excel, the columns are the exact same as Sheet 1, the only difference can be more/less rows (along with the updates for each row).
You can use conditional formatting.

Excel: How to compare sheets from 2 different workbooks for differences

I have an original excel file that I have ran a simulation that inputs financial data. I made a copy of this file, and wired the formulas up differently to try and increase calculation performances.
I now have 2 workbooks, the original and the final. I want to compare each sheet from each of the workbooks together to make sure that the financial numbers have remained the same, to make sure the new formulas are not effecting the numbers received.
I have tried to put copies of the two sheets into one workbook, name them April12 and April15. Then insert a third sheet. In cell A1 of the third sheet, I wanted to use the formula
=April12!A1=April15!A1
to get TRUE/FALSE values. But the formulas in these sheets reference many other sheets that are not in this new workbook, so all of my numbers turn up as #REF.
Iv googled many different ways of approaching this but I cant seem to get any of them to work. Does anyone know a simple way I can compare just the values from 2 sheets from 2 different workbooks to find out if the numbers have remained the same or have changed?
Note:I am using excel 2010.
I think you already know how to verify data using formula so is the problem to refer to a row in a different workbook ? if so, following might be helpful :
=[yourFile.xls]SheetName!$Col$Row
this way you can update your formula like(yourFile.xls refers to the complete path including the file name) :
=[file1.xls]April12!A1=[file2.xls]April15!A1

Complex VLOOKUP with dynamic sheet name

I'm trying to perform a vlookup across multiple sheets in an elegant way, rather than with a vlookup nested in an IF function.
Column A has the account number and Column I has the manager responsible for that account. Each Manager has their own sheet. I was hoping to make vlookup look at a specific manager's sheet, find the account number in Column A, and return the info in Column K. I tried to use INDIRECT to make it do that:
=VLOOKUP($A2,INDIRECT($I2 & "!$A:$P"),11,FALSE)
With this code, I keep getting #REF instead of what is in Column K in the manager's sheet. How can I fix this?
Thanks!
I can't see your spreadsheet but if your sheets are named after managers I am willing to bet that those sheet names have some kind of character( like space) that forces referencing sheets in single quotes.
Assuming that is correct simply change your formula to:
=VLOOKUP($A2,INDIRECT("'" & $I2 & "'!$A:$P"),11,FALSE)
Also you can diagnose this issue with "Evaluate Formula" located in "Formulas>Formula Auditing", in there step through all steps that this formula has, and note when does that error shows up.

How To Display Excel rows on selection of first Excel Column Value

I have Two Excel sheets. My requirement is when I select a reason value from one Excel sheet Reason_Name column, it will display that reason value in a second Excel sheet.
So using Macro, I want to display the second Excel rows on selection of reason in first Excel.
Please Help.
This is the first Excel sheet - Reason_Name column contains Reason1, Reason2, etc.
alt text http://www.freeimagehosting.net/uploads/a10d6be7a5.png
This is the second Excel sheet
alt text http://www.freeimagehosting.net/uploads/99e0ff4cdb.png
Here's something that may get you started. (I think this is close to what you would like to do.)
Create a named range for the data on the second sheet. Named "new_range" in my example.
Then create the following procedure in a new module:
Sub FilterSheetTwo()
Worksheets("Sheet2").Range("new_range").AutoFilter Field:=6, Criteria1:="Reason1"
End Sub
When you run this procedure, it should filter the results on Sheet2.
You can then hook this procedure up to an Worksheet_Change event on Sheet1.
If you can sort your Reason column on the second sheet and place it as the left-most column you don't need a macro--you can do this using VLOOKUP. Steps:
Sort Data by your Reason column on the second sheet.
In each column of the first sheet enter the following formula:
=VLOOKUP(E2, DataRangeOfSheet2, ColumnYouWantFromDataRange)
See VLOOKUP for more info.