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

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)

Related

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

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.

look for Column heading and sum up

I have been working with a excel file with a lot of data, which is arranged in 2 sheets.
I would like to get data from sheet 1 to sheet 2 with reference to the column headings.
For example:
So if I want to find the sum of function 1 person A with criteria 1, the command have to go and find the heading "sum of function 1" in sheet 1 and choose the data that are only under criteria 1 and sum it up in sheet 2 cell D5. (By using column heading reference instead of cell reference).
The table range is A2 : U80.
Thanks.
First you have to format your data as table (select the data -> Menu Insert -> Table). Then you rename your table, for example Table1. Let's say one of the columns you want to sum on the sheet2 is called ColumnName.
On the sheet 2 you write a formula
=SUM(Table1[ColumnName])
The result will be what you are after.
You should try it by SUMIFS(). Syntax will be
=SUMIFS(AgeRange from sheet1,NameRange Sheet1, Name cell Sheet2, PlaceRangeSh1, Place Cell Sh2)
Tell me if requires further help.

Compare Excel sheets values to update a third value

Example file So I have two sheets that each have lists of part numbers, plant where they come from and two columns on costs. What I need to do is scan them and if Sheet A and Sheet B both have a row with matching part numbers and the plant they come from, then A's two cost values are updated to match B's costs.
The next step is then to highlight all cells in Sheet A that are not on Sheet B and highlight all cells in Sheet B that were copied to Sheet A. I think this last part can be done at the same time the cell is being copied I'm just not sure how to do any of this.
This is a formula method.
Because you will not be changing all the values and I assume you want to keep those that do not have a match, then in an empty column next to the figures on sheet 1 put the following formula:
=IFERROR(INDEX(Sheet2!F$3:F$7,MATCH(1,INDEX((Sheet2!$D$3:$D$7=$A3)*(Sheet2!$B$3:$B$7=$C3),),0)),G3)
Then copy over one column and down the the end of the data.
The INDEX((Sheet2!$D$3:$D$7=$A3)*(Sheet2!$B$3:$B$7=$C3),) will create an array of 0 and 1's the same size as the data reference on sheet 2. In this instance it will create a 1 dimensional array that is 5 objects.
The position of these objects of 0 and 1 are relative to the rows. So for the first formula the return array will be {0,1,0,0,0} because only the second row of the data matches both the plant and the part number.
The MATCH(1,INDEX(...),0) then finds the first object in that array that is 1 and returns the relative position, in this case 2 as it is the second in the array.
The Outer INDEX(Sheet2!F$3:F$7,...) then returns the value in the range Sheet2!F$3:F$7 whose relative position is equal to the 2 passed from the MATCH(). So Sheet2!F4.
If no MATCH is found then the whole thing will throw a #N/A error so we capture that error with IFERROR(...,G3) and tell the formula to return the value in column G instead.
This will give you all the proper values:
Then you can copy and paste just the values back to the original spots and hide the columns with the formulas:
Sheet2 for reference:
If you want vba to do the last part of copy and past and hiding then use the macro recorder and then clean up the code.

vlookup if name is matched display employee id

Ive never used vlookups i have a spreedsheet not sure if this is the right function. I have two sheets
Sheet 1
first name last name username
Sheet 2
first name last name employee id business unit
I need in column D on sheet 1 to have employee id ive below. Pay no attention to column letters and sheets because i moved to another sheet to try getting this right.
=MATCH(B11,Sheet1!C:C,0)
Any help is much appreciated.
So you realize you have to match both first and last names? There are several ways to accomplish this depending on how many employees you have in sheet 2: a) small list could a two-column search using array formula; b) large list just create another column in both sheets joining last & first names and do a MATCH or VLOOKUP on them.
Since your needs are simple and to illustrate option (b):
Insert a column in both Sheet1 and Sheet2 after the "last name"; you should now have an empty column C in both sheets.
Assuming you have column headers in row one, and thus data starts in row two, set cell C2 in both sheets with function =B2&","&A2, then fill-down that formula on both sheets in all rows.
Set Sheet1 cell E2 to formula =VLOOKUP(Sheet1!C2, Sheet2!$C:$D, 2, False), and fill-down that formula in all rows.
Voila, employee IDs on Sheet1. I do have to say this is so Excel 101. There are all sorts of examples and tutorials on this easily found using even the most trivial Google searches.

Excel Macro that reads the number of rows in another spreadsheet and fills down formulas

So I have two spreadsheets. One of them contains a lot of data with each column titled a few times, so the actual data for each column ends up starting in row 4 and on. In my other sheet (Note: they are in the same excel file though), I have some of the columns titles, a formula in row 3, and then the output of my formulas from rows 4 and on. Essentially, I have made formulas that check certain columns and the information in them for each row that there is data. What I want to do is have a button macro that looks at how many rows of data there is in that first spreadsheet starting at row 4, and then automatically have my formulas in the second sheet fill down to that certain amount of rows.
I have attempted to write the macro, but I end up getting a run-time error. Here is the code:
Range("A4:S4").AutoFill Destination:=Range("A4:S" & Cells(Row.Count, "Core Data2!A").End(xlUp).Row)
A-S are the amount of columns I have in my formula sheet. Core Data 2 is the spreadsheet with all the data
If someone could please show me how to get this to work, that would be greatly appreciated.
Use the following code for each of the columns A to S:
Range("A4:A" & Sheets("Core Data2").Range("A" & Rows.Count).End(xlUp).Row).Formula = "=[INSERT FORMULA HERE]"
In this example, A is the column that will be 'autofilled' up to the amount of rows populated with data in column A of the 'Core Data2' sheet.