Replace reference in formula with precedent - vba

I have an excel file with three sheets (1,2,3), in the first sheet are primary data, in the third sheet are final data for output and the second sheet is bridge between them. I need to update formulas in the third sheet so I can delete the second sheet.
For example, there is value in sheet "1" in cell A1, then in sheet "2" is C5='1'!A1, in sheet "3" B4='2'!C5, and I need to get in sheet "3" B4='1'!A1. I need to do this for thousands of cells, therefore it is impossible to do it manually and I was thinking about using macro, but I was unable to create such macro. Can somebody help me?
This question raised because the bridge in sheet "2" is complex and not only assign one value from sheet "1" to one cell but it also add up several cells from sheet "1" together, therefore there is not any simple way to replace the bridge by vlookup or similar function.

It's pretty difficult to answer this question the way you have written it. This is because it seems all the cells in Sheet3 point to a "random" spot in sheet 2. If there is no rhyme or reason to how sheet pulls its numbers, replacing the formulas could be hard. However, try this:
If sheet 3 cells only EVER refers to a single cell in sheet 2, and sheet to only EVER refers to sheet 1, then you can go to sheet 2, and press CTRL + H. This will bring up the "find and replace" function. Replace all instances of "=" with "ZZZZ=". When you look to sheet3, you will see that instead of giving the values calculated off of sheet1 through sheet 2, a cell in sheet3 could say something like "ZZZZ='sheet1'!A1+'sheet1'!B1", because that's the value of sheet 2 that it points at. From there, copy and paste all of sheet3 to values only. Then, CTRL + H again and replace all instances in sheet of "ZZZZ=" with "=".
However I doubt this will work as if sheet2 contains values used elsewhere in sheet2 to calculate, or if sheet3 refers to things in other ways, this will fall apart.

Related

Auto populating rows from another sheet conditional to a specific cell value

Hello i am trying to autopopulate rows from another sheet if a specific value if found in a specific cell. So far, i managed to do it manually by adding this line in Sheet #2 for each cell.
=IF(OR('Le 2250'!$C48="Nouveau locataire",'Le 2250'!$C48="Décès", 'Le 2250'!$C48="Retention"), 'Le 2250'!$B48,"")
I am trying to create a vba script that will generate each column in Sheet#2, and that will dynamically update regarding if i add a row in Sheet 1 or delete it.
Sheet1 is:
Sheet2 is:
Your help is appreciated
What your looking for is the INDIRECT function
As an example:
=CELL("contents",INDIRECT("Sheet1!B5"))
This always pick up the value in Sheet1 Cell B5, regardless of changes in Sheet1.
For more information: Excel INDIRECT Function
Edit: To directly answer the question with INDIRECT.
=IF(OR(INDIRECT("'Le 2250'!C48")="Nouveau locataire",INDIRECT("'Le 2250'!C48")="Décès"),CELL("contents",INDIRECT("'Le 2250'!B48")),"")

Find column that meet a criteria and copy other cells in that row to a new sheet

I'm trying to create a Macro that will find text in a column (D) and if a criteria is met, then copies the row into to another sheet. The Criteria I am looking for will be not be the only text located in the cell. For Example the criteria could be "Prodigy" but the Cell could contain "Prodigy, Prodigy Tubing Set".
I have a Sheet called "Sheet1" which has all the raw data with headers. The column that has the values to meet the criteria is "D".
I have other sheets where the data will be copied to. For example one of the Sheets will be titled "Prodigy", another will be "Prodigy Tubing Set". There will up to 20 other sheets.
Macro: Given row X copy specific cells from that row to a new sheet
I tried using the code the person in the link above built but it would only work if my criteria was the only thing in the cell.
A picture of what my spreadsheet will look like is below.
I am pretty new at this and would appreciate any possible assistance. Hope this makes sense.
I think the function you are looking for is InStr.
The example you posted has this: If cell.Value = "Card" Then
Instead, you will want something like this: If InStr(cell.Value, "Prodigy") > 0 Then
Of course, you will probably replace the literal "Prodigy" with some cell value or variable.

Lookup function in multiple sheets data

I have multiple sheets of data and I want to make it in one sheet (All of them are in the same workbook). Link to the excel file.
I tried to use Hlookup function in excel file, something like below:
=HLOOKUP("University",Sheet1!$A$1:$G$2, 2, FALSE).
But, since I have more than 100 sheets of data, I want to find a way to drag the function and auto generate the function below the 2nd row. I have tried to use indirect function by setting a reference column in front as below but cannot deal with it.
=HLOOKUP("University", 'INDIRECT(A3)'!$A$1:$G$2, 2, FALSE)
My next option is VB code. But, I am new to VB. Anybody can help on it?
Place your individual sheet names in column H of the Summary sheet and the row number in column I (as helper columns) and write this formula in cell A2 of the summary sheet.
=IFERROR(HLOOKUP(A$1,INDIRECT($H2&"!A1:G"&$I2),$I2,0),)
and drag to column F and down for as many sheet rows combos you have. I used 10 rows but you can obviously make it longer or shorter as neeed.
When you are done you can filter on 0 in column A and remove any lines with no data.
If your sheet names have spaces in them, you'll need to adjust the INDIRECT formula to this:
INDIRECT("'"&$H2&"'!A1:G"&$I2)
best way would be "defined names" + INDIRECT + HLOOKUP (or LOOKUP) like:
defined names
name: SList
formula: =MID(TRANSPOSE(GET.WORKBOOK(1))&T(NOW()),FIND("]",TRANSPOSE(GET.WORKBOOK(1))&T(NOW()))+1,255)
formula in cells: (this in A2 then simply autofill to G2 and thenn everything down) (you'll get a row with 0's between the sheets, which can be filtered out or deleted later (copy/paste values))
=IFERROR(HLOOKUP(A$1,INDIRECT("'"&INDEX(SList,COUNTIF($A$1:$A1,0)+2)&"'!$A:$G"),$H2,0),"")
Set H2 to 2 and for H3: (autofill down from H3)
=MAX(($H2+1)*($A2>0),2)
works perfectly for me LINK
No manual typing of sheetnames or something like that (only Column H:H as helper). Youll get rows's with 0's every time a new sheet is selected which can be filtered out. (or if you copy/paste values also can be deleted)
the +2 at ...st,COUNTIF($A$1:$A1,0)+2)&... simply tells to start with sheet 2 (if summary is the first). You may change it to +1 if you want to lookup starting with the first sheet.
Assuming you already have all 100+ sheet names typed out in column A, this will work whether or not you have spaces in the sheet names:
=HLOOKUP("University", OFFSET(INDIRECT(ADDRESS(1,1,1,1,A2)),0,0,2,7),2,FALSE)

Hyperlink after Vlookup

This simple thing is eating my brain out. Here is the challenge:
I have 2 sheets in the same workbook. Say Sheet 1 and Sheet 2. I want to Vlookup for the value present in Sheet 1 Column A and Sheet 2 column B. If the value is found i want to put a hyperlink in Sheet 1 Column A to point it to Sheet 2 Column D. In simple words, there are program names present in both the sheets and associated risk in sheet 2. If the program is present in both the sheets then i want to navigate directly to the risk present in the Sheet 2 upon clicking the program name in Sheet1.
I am attaching the sample file with this thread. Please somebody help me. I have tried with vba and normal formulas. Nothing is being worked out.
SAmple file can be downloaded from here
Here's how you can do that with a formula. You'll need to change the workbook name in the HYPERLINK formula to match yours.
=IF(ISERROR(VLOOKUP($A1,Sheet2!$B:$B,1,0)),"",HYPERLINK("[StackTest.xlsx]'Sheet2'!D"&TEXT(MATCH($A1,Sheet2!$B:$B,0),"#"),"Click Here"))

How do I increment cell in Excel VBA script?

I have a data in excel which I want to make a VBA script to copy it into a new worksheet but in a different way.
For example, I have this in sheet1 in A1~A3 cells.
Adam(A1)
Sam(A2)
Smith(A3)
I want to use these cells and create the following in another worksheet using refedit control.
Adam(A1)
Adam(A2)
Adam(A3)
Adam(A4)
Sam(A5)
Sam(A6)
Sam(A7)
Sam(A8)
Smith(A9)
Smith(A10)
Smith(A11)
Smith(A12)
I have refedit control in place in VBA script, but I'm not sure how to increment cell numbers to make it copy and paste into a new worksheet. I would like to use refedit control so that I can assign any cells and make it copy and repeat itself. How do I do this in VBA script?
Check out the Range Rows, Cells, and Address properties. This should help. Your question is too vague for a direct answer.
(This will get you started.)
Range.Row Property
http://msdn.microsoft.com/en-us/library/bb221550(office.12).aspx
Returns the number of the first row of the first area in the range. Read-only Long.
Example
For Each rw In Worksheets("Sheet1").Rows
If rw.Row Mod 2 = 0 Then
rw.RowHeight = 4
End If
Next rw
To increment cells in Excel VBA, you can use the Offset-property of the Range-object, e.g.
ActiveCell.Offset(1, 1).Select
will select the cell one row down and one column to the right of the active cell.
To add to Geoffrey's answer about active cell - it would also require that you activate the sheet you are looking to input your values if it is a different sheet from the one that is currently active. Additionally you would have to activate a cell to use activecell and the activecell offset property.
For example
'Activates the name of the sheet you would like to activate
Sheets("Sheet2").Activate
'Activates cell A1
Range("A1").Activate
'Activates cell one row down, one column right
ActiveCell.Offset(1,1).Select
'if current sheet is not activate you just do Sheets("Sheet2").Range("A1").Activate
The offset property of ActiveCell refers to other cells based off of the current active cell.
For example-
Offset(row,column) -
First Argument -Positive values as the first argument refer you to rows below the current active cell and Negative values refer you to rows above the current active cell
Second Argument-Positive values as the second argument refer you to columns right of the current active cell and Negative values refer you to columns left the current active cell