How do I insert a row in excel and include the inserted row in a formula? - vba

Example:
I have a cell "A1" that sums up some values in a row "IF"-something: =SUM.IF($C$5:$C$10;"Blue";$D$5:$D$10)
meaning: If columns C5 to C10 contains the word "Blue" in any row for example. "C7" and "C9", then the sum of "D7" and "D9" will be shown in "A1".
My problem:
If I insert a new row "5", then I want the formula to contain this row as well:
=SUM.IF($C$5:$C$11;"Blue";$D$5:$D$11)
But what happens is that the formula is now:
=SUM.IF($C$6:$C$11;"Blue";$D$6:$D$11)
So the formula contains only the original 5 rows "5-10" and now named "6-11".
How do I make excel expand the formula to include the new row aswell so it sums up from "5-11" =SUM.IF($C$5:$C$11;"Blue";$D$5:$D$11)?
(I know I can make this work with a table, but this is a thought example and not my real situation. Actually I insert 5 rows at a time, and some cells are merged, so I can't convert the range of data into a table)
Any help is greatly appreciated.

This can't be done. Set the row range reference in the formula to one row above you actual list, then everything should work.
For example, leave row 5 empty. Hide the row if you like. In cell A1, use the formula =SUMIF($C$5:$C$10,"Blue",$D$5:$D$10) (starting at row 5). Start entering values in row 6.
Now you can right-click Row 6 and Insert a new row, and the formula will continue to work as required.

Related

Copy data from another sheet with 4 rows between each entry

I am working with three excel sheets within the same workbook, Data, Calculations, and Results. As you will see, the entries in column A are the focus.
Using the formula Data!A# (row number), those entries from the A column of Data are copied onto column A of the Calculate page. Between each entry from Data, there are three rows of calculations. On the last page (Results), I am looking for a formula/VBA code that will allow me to grab column A from Calculate without the three rows in between them.
Currently, I am experimenting with an offset function: OFFSET(Calculate!$A$2,(ROW()-1)*2,0). When I copy the forumla down, zeroes appear in some rows in place of the actual values. (Note A1 of Results is =Calculate!A2.)
How can I copy the entries from the Calculate sheet without a function returning zeroes as placeholders?
Data Sheet
Calculations Sheet
Results Sheet
You can accomplish this using the indirect function:
=INDIRECT("Calculate!$A$"&(ROW()-1)*4+1)
With that formula in A1:A4 of the results sheet, you should get the values you want from A1, A5, A9, A13 on the Calculate sheet.

Trying to Insert blank rows x number of times, x = cell value

I am trying to insert a specific number of blank rows, which is based on a value in a cell. This value in the cell is a count function from a table.
I have an "Import Table" sheet which contains all my data. Next to the table I have a couple count functions, which count general categories coming from the table. For example on the "Import Table" worksheet Cell J8(Domestic Equity), Cell J9 has the count function which for this case comes to "11". I now want 11 rows to be inserted at a specific spot in my "Analysis" worksheet. In this worksheet there are heading also names like the count headings(domestic equity).
So under domestic equity I want the rows to be insert. In the analysis sheet a function is already created in the first row under domestic equity, so the new blank rows have to be inserted under that value in this case under row 6.
The formula already existing in cells (A6,B6,C6,D6,E6) then have to be flash filled into the newly created white rows.
I attached 2 images to hopefully clear up my questions.
Thanks!
Range("A1").Resize(11, 1).Insert (xlShiftDown)
OR
Rows(1).Resize(11, 1).Insert (xlShiftDown)

how to create a column that only gets the matching value from another sheet in EXCEL

i would like to create an extra column in sheet one which displays a character (for example G) after it finds the matching values from sheet 2.below are two screen shots i have taken for all your conveniences.
please note,in sheet 1 i have marked two rows with identical bs_cd 6374 which matches the bs_cd 6374 in sheet 2 also.what i want is to have a character G in sheet 1 under column G.
thanks in advance
Insert into the cell G2 this formula and drag it down:
=IF(VLOOKUP(B2;Sheet2!$A$2:$A$100;1;FALSE)=0;"";"G")
Change $A$2:$A$100 to your range in sheet2

Excel VBA - selecting the range from first row to the last row

I have a problem with VBA code. I have a sheet with a lot of data around the cells I want. I need to select data in column F, but the position of the first and last cells between the range is to be selected is changing up and down. I created the non empty cells in row X where there is no data do the LastRow function has any refernece but now I dont know how to select the first row
thx for help
If F1 is empty, this selects the first cell with data in the F column
Worksheets("Sheet1").Range("F1").End(xlDown).Select
If F1 may be non-empty you can add a check to see whether it contains text.

Copy corresponding values from reference to a new list in Excel 2007

I hope somebody can help me; I've been trying to figure out how to do this all day long.
I have one sheet with a list with corresponding values, e.g. Columns A, B, C make a group of values that have to be together.
In another sheet, I have some values from Column A, but not all of them, and want to automatically add the corresponding columns B and C to it.
So I thought about making a macro that copies the first value from Column A in the incomplete sheet, searches for it in the reference sheet, copies the corresponding values from B and C, pastes them next to A in the incomplete sheet, then copies the next value from A and searches for it in the reference table, and so on...
I tried but couldn*t make it work - any ideas? I've wasted way too much time on that problem already! Would do it by hand but have like 40,000 rows of data.
If you know how to do it, help would be MUCH appreciated.
Based on these assumptions:
Complete data is in Sheet1, columns A:C starting at row 2 (Headings in row 1)
Incomplete data in sheet2, column A starting at row 2 (Headings in row 1)
put this formula in sheet2 cell B2
=VLOOKUP($A2,Sheet1!$A:$C,2,0)
put this formula in sheet2 cell C2
=VLOOKUP($A2,Sheet1!$A:$C,3,0)
copy these formula down for as many rows as you have data
you can leave the formulas in place, or copy paste values to make permanent