I have two pre-filled spreadsheets ('main data' and 'variable prices') and VBA code that formats and copies one row from 'main data' to a 'results' sheet using some values from 'variable prices'.
On the first sheet a certain value is calculated using a cell in, say, BR column, when row is copied to the 'results' sheet that value is moved to another column, BY.
Something terrible happened and now the formula that calculates total on the 'results' is not updated and takes irrelevant value from BR column.
How to manually (I am guessing that when I put this together half a year ago the reference was updated automatically, but got destroyed when my boss edited/copied values or whole rows of data from other files, deleting the files after - I get "broken link" message now) set it back?
I hope this is legible. This is my only VBA experience, its operation is still somewhat of a mystery..
Thank you!
When you copy data as a formula and you want to keep referencing parts to the originating column/cell, you can "lock" the references. Example in a cell:
=A1, when copied two columns to the right would result in =C1 or
=A1, when copied tow rows down would result in =A3.
You can fix/anchor either the column, or the row or both in a formula by putting a $ in from of the reference. =$A1 remains =$A1 even when copied two columns to the right. =A$1, remains =A$1, even when copied two rows down. =$A$1 will always stay =$A$1, wherever you copy this to.
Alternatively, if you only want the value (not the formula), use paste.value or
cells(ref.target).value = cells(ref.org).value.
Oh forgot to tell you, when you highlight a cell address (A1) and you press F4, you can toggle between 4 stages from $A$1, $A1, A$1, A1
Related
I'm importing a text file into one sheet, eliminating un-needed lines, while formatting the data on the second sheet.
I have all the formulas on the second sheet set up, referencing cells on the first sheet.
The problem is that after deleting the un-needed lines and the data moves up, the formulas for the deleted lines say #ref. I want the formulas to use, say Sheet1!B2 no matter what data is there.
I see that Indirect works, so the next question is, how can I copy the Indirect function down a colum of 500 rows with each one having the right reference?
Thanks
I had this same problem recently so just passing along the answer I got. Index functions will help. Below you can see one where the sheet name is reference in cell a1 and it will return the value in cell a2 of the corresponding sheet.
=INDEX(INDIRECT($A1&"!2:2"),COLUMN(A:A))
If you only need to reference cells on the same row, including cells on different sheets on the same row, there's an easier way than Indirect.
If you write in A42:
=#B:B
it will look up B42.
If you write in A42:
='Sheet 2'!#X:X
It will look up X42 on Sheet 2.
If you delete the top rows on Sheet 2, the formula on Sheet 1 will point to the new X42 - no #REF! errors.
As long as your formulas in Sheet 1 just need to reference cells on the same row in Sheet 2 - so the formula in 'Sheet 1'!A42 might want 'Sheet 2'!X42 but not 'Sheet 2'!X43 - you can just put the column names as inputs into the formula. Otherwise you'll need Indirect.
For bonus points, name the columns in Sheet 2, so instead of ='Sheet 2'!#X:X you could write =cust_DateOfBirth for example.
I have an excel worksheet with 1153 columns. I need the values in each column to be multiplied by those in the first column. I have inserted blank columns between each column to add the results and right now I am doing this by hand, but it is taking too long. Here is an example:
Example
EDIT- Right now I am copying the formula $A1*adjacent cell into each blank column and then simply double clicking to population the rest of the column. My hope was that there was an alternative.
Is there VBA code, a macro, or a formula that would make this process faster? Thank you.
It sounds like your looking for some form of direct addressing. For example, the relative cell address "A1" will change if you copy the address to another cell, but the address"$A$1" will always reference cell A1 regardless of where you copy it to.
However you can fix only the row or column with the address "A$1" or "$A1" so that the address will always reference the same row or column, but will update the other as it's copied. In your case you probably want to fix the column with "$A1".
I am attempting to use an IF statement to check whether the sum of two cells from another Excel sheet is greater than or equal to 1.
For a sheet called Test1 with the values of interest in column C, this is what I have so far, which works fine:
=IF((Test1!C1+Test1!C2>=1),1,0)
In column B on a second sheet that I'll call Test2, I want to copy this formula down 200,000 rows. However, if the aforementioned formula is in cell B1, for the formula in B2 I would like the formula to read:
=IF((Test1!C3+Test1!C4>=1),1,0)
I want to copy the formula down the column so that the second cell reference in the formula in the first row does not become the first cell reference in the formula in the second row (eg. it would go C1+C2, then C3+C4, C5+C6, etc.).
I have tried manually entering the formula for a few rows, highlighting those, and copying them down but can't get the desired cell reference pattern. If I highlight and drag these first three formulae down another three rows, C4 and C5 are repeated and not in the correct pair.
=IF((Test1!C1+Test1!C2>=1),1,0)
=IF((Test1!C3+Test1!C4>=1),1,0)
=IF((Test1!C5+Test1!C6>=1),1,0)
=IF((Test1!C4+Test1!C5>=1),1,0)
=IF((Test1!C6+Test1!C7>=1),1,0)
=IF((Test1!C8+Test1!C9>=1),1,0)
I have tried using OFFSET() within this formula but couldn't get it to work. I am basically just wanting to add 1 to each of the cell references in the formula, as compared to the previous row (but not to actually add 1 to the value of that cell, as would happen with C1+1 for example).
Any insight would be greatly appreciated!
If you plan on copying this down 200K rows then you will want the absolute simplest formula that accomplishes the stagger. Avoid the volatile OFFSET function or be prepared to spend a lot of time waiting for random calculation cycles to complete. A volatile function will recalculate whenever anything in the workbook changes; not just when something changes that involved the formula in the cell.
=--(SUM(INDEX(Test1!C:C, (ROW(1:1)-1)*2+1), INDEX(Test1!C:C, (ROW(1:1)-1)*2+2))>=1)
The following formula should do the trick:
=(SUM(INDIRECT("C"&ROW()*2-1);INDIRECT("C"&ROW()*2))>=1)*1
And that's the version using IF:
=IF(SUM(INDIRECT("C"&ZEILE()*2-1);INDIRECT("C"&ROW()*2))>=1;1;0)
You say I am basically just wanting to add '1' to each of the cell references in the formula but appear to be incrementing by 2, so I am confused but an option might be to apply you existing formula to 400,000 rows, together with =ISODD(ROW()) in another column, then filter on that other column to select and delete those showing FALSE.
Excel's autofill won't do the 2-cell shift that you're looking for. You can use the functionality that is there.
Put =IF((Test1!C1+Test1!C2>=1),1,0) in the top cell and drag a copy to the second row (it will be =IF((Test1!C2+Test1!C3>=1),1,0) but that's okay). Now, put 'A' and 'B' in the next column. Select all 4 cells and copy them down 400k rows.
Use filter to delete rows flagged with 'B' and delete the blank rows.
(Select blank rows with [F5] click Special and select Blanks, then right-click and delete)
Here is all you need. It's fast and nonvolatile.
=--(SUM(INDEX(Test1!C:C,ROW(1:1)*2-2):INDEX(Test1!C:C,ROW(2:2)*2-2))>=1)
Copy it down as far as you like.
I have the formula below that I'm using to link to a certain sheet and cell in my workbook that contains a graph for each entry. On the sheet I link too, each graph is about 20 cells down from the previous one. I have over a 100 graphs now and it will grow in time so I was trying to use the HYPERLINK formula rather than the Hyperlink button for this. I thought I would be able to just insert the formula in the first row, paste it in the second row with an added 20 cells, highlight the two and drag it down but it will not count in increments of 20.
Is this even possible?
=HYPERLINK("#'Trends'!A25","Click To View Trend")
I'm thinking you will have to use some type of concatenation to get the behavior you are after. To do this, you may want to employ a "helper" column. For example, put the "numbers" you are after in column B -- below you will see that I incremented it by 5.
Now your HYPERLINK formula in cell A1 is written as:
=HYPERLINK("[Book1]Sheet2!A"& B1,"Click Me for Sheet2, Cell A"&B1)
(Assuming the workbook is called Book1. Now, I can drag that formula down and it will update "dynamically" to account for the changes in column B.
I have a spreadsheet where I want cell formula to always look at a specific cell, even if rows or columns are inserted and the specific cell moves. Effectively, I always want to look at the 'top' cell of a table, even if new rows are inserted at the top of the table.
eg. Cell A2 has the formula[=$E$2]
Now I highlight row 1 and do Insert Row. The formula in A2 now says [=$E$3] but I want it to be looking at the new row 2.
The dollars will keep an absolute cell reference no matter what I do to the 'referencing' cell, but I want the cell reference to be absolute no matter what I do to the 'referenced' cell. If that makes sense!
Effectively, I have a 'table' in excel 2007 and I want to always reference the top row. The trouble is that rows are added to this table from the top so the top row keeps moving down to make room for a new top row.
--- Alistair.
Try =indirect("F2"). This will work if you know that the top-right cell of the table is always going to be $F$2.
You could also use the Offset Function:
http://office.microsoft.com/en-us/excel-help/offset-function-HP010342739.aspx
or
https://support.office.com/en-us/article/offset-function-c8de19ae-dd79-4b9b-a14e-b4d906d11b66
Building on #ktdrv's answer (I can't comment): =indirect("F"&ROW()) would be $F2 if it's a reference that needs to be dragged down multiple rows. A minor drawback with =indirect() is that you lose cell reference highlighting for the formula.