How to duplicate cell data in excel between rows if the cells are empty when another cell matches - vba

I know the title is really long winded, I will try to explain
I am trying to get Magento products into Zen Cart (background only - shouldn't be relevant).
I have an excel 2010 xls spreadsheet and in it I have a load of product data: skus, prices, categories, etc... you get the idea. I have each of the products along with their data listed once, each with a unique SKU field.
But... Some of these products are in more than one category and the way I am importing, each product needs to be listed multiple times, once for each category.
So, I have done an sql dump which contains two columns; sku and category. I have pasted these values into excel as new rows, so now I have a situation like this (with a lot more entries):
As you can see for each sku (left highlight) there is one entry containing all the data apart from the category (right highlight) and then there is an additional entry for each category it belongs to which contains only the category and sku but none of the other data.
So, what I need to do is some how copy all the data (apart from the categories column) across all cells with the same sku. Does anyone have any idea how I can achieve this without hitting Ctrl+V several hundred times. I realise VBA can probably handle this pretty easily, but I dont have a clue on that front.
Any help greatly appreciated

I hope you’re willing to use a second sheet, and to reference the data rather than actually copying.
On Sheet2, set A1 to =IF(Sheet1!A1="", "", Sheet1!A1).  Drag (extend/fill) this down to A500 (as much data as you have on Sheet1, or further, to allow for growth).  Also drag A1 over to AA1 and then drag that down to AA500.
Then set B2 to =IF($AA2="", Sheet1!B2, B1), drag it to Z2, and drag B2:Z2 down to B500:Z500.
P.S. If any of your data (columns) are dates, you will probably need to explicitly format them as dates on Sheet2.  Ditto for any other values that are formatted any non-default way (e.g., Currency or Percentage).  It may be necessary to do this only to cells that have values in them (and not blank cells).

You don't need VBA, unless you need to do this many times.
Assuming the sheet with your data is called Source and the sheet with the result is called Dest, you can get what you want following these steps on the sheet Dest:
On A1 type =Source!A1
On A2 type =IF(ISBLANK(Source!A2),A1,Source!A2)
Select the range A1:XX1 (where XX is the last column of the sheet Source)
Press Ctrl+R (to copy the first cell to the right)
Select the range A2:XX## (where ## is the last row of the sheet Source)
Press Ctrl+R and Ctrl+D (to copy to the right and down)
Here is an explanation of what's going on:
The first row is copied from the Source as it is.
Each cell of the second row is copied from Source only if that cell is empty, otherwise the cell above is copied.

Here's the quick and dirty solution:
Select the columns you need to be filled
Press Goto Ctrl-G
Special `Alt-S'
Blanks (Alt-K, Enter)
This should select all blank cells. Now type =B2 (assuming you're in B3, i.e. use the cell above the active cell) Important: Press Ctrl-Enter instead of Enter to enter the formula.
Done!

On a new Worksheet get the numbers 1-26 running across the top in Row1 by typing 1 in cell A1, 2 in cell A2, and then selecting those two cells and filling through Z.
Now in A2 type the following formula =VLOOKUP(Sheet1!$A1,Sheet1!$A:$AA,VALUE(A$1),FALSE)
Fill this formula in the Range A2:Z## (where ## represents your last row of data).
Then copy Row1 from Sheet1 to Row1 on Sheet2.
This formula will copy the rows of data straight down into the empty rows below them (assuming the sku only changes where there is a row of new information.
This will then all be active formulas, so I would recommend selecting all on Sheet2 and right-clicking in cell A1, and paste special by value.

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?

IfError, leave formula in place/don't do anything?

I have a spreadsheet, where I'd like to drag down a particular index/match formula, but where the formula does not return a value, I'd like it to keep the formula that is already in place (which sums up a few of the items below it).
I know that you could just use the cell reference for the if_error part of the formula, but this would return the value of the cell as it is now, and wouldn't use the current formula to generate a new value based on the values returned by the index match formula.
I have attached pictures below. Basically, I want to leave the sum formulas as is, but just be able to drag down that first index formula (the actual spreadsheet I'm dealing with has many different spaces, and is very long, otherwise I'd just copy the formula manually).
If this isn't possible, are there any other solutions? Another thing I tried was for each index/match that didn't return a value, I had it return the formula as a string, and then I'd copy/paste special with values, replace the column in the formula that is a string to the column I'm looking for, and then it would evaluate the formula that was, before, a string. But then you lose the formulas for all the other cells.
So the issue is that some cells are used to sum, and I don't want to drag the formula over those cells, but at the same time, I do need to use the formula over the whole range, otherwise it would just take too long.
Once you put a formula in G1, the previous formula in that cell is no longer available, so referencing G1 in your new formula would just produce a circular reference.
Instead think of a formula that combines both formulas into one: it should detect in which situation it is and then perform the appropriate calculation.
In your case, I think this formula will do what you want:
=IFERROR(INDEX($M$3:$M$9, MATCH(F1,$L$3:$L$9)), IF(E1="", "", SUM(G2:G4)))
Put it in cell G1 and copy it down.
Note how it looks at column E to decide whether it should do the sum. I also adapted a bit the part you already had, by making some references absolute (adding some $), because the area in the L and M columns is positioned at fixed rows.
Add a helper column in row H for your Index-Match formula and copy it all the way down. Then, in row I do an if statement. If row H meets the criteria you want, do that, else use row G.
So I think I found a good solution, especially in the case where you are going to be using the spreadsheet over and over, and the format won't change much. This might be too specific for anyone to use, but posting it just in case someone gets some use out of it.
First I created two macros, one to hide the sum rows, and another to unhide all the sum rows. I got the sum rows from another column by copying all the formulas across to the new column I'm looking at. Numbers will of course be wrong, but the sum formulas will be what we want to keep. You can speed this up by finding "sum" in formulas and then selecting all of the results.
Next, use the macro which hides all the sum rows.
Next, create the index formula in the first row. Control shift down to select all rows beneath. Then, "find", and "go to special" and select "only visible cells", and then hit F2, and control enter, and this will copy the formula down to all the visible cells, ie the non-sum cells.
Then use your unhide macro, and it should be golden!
You can use this technique for any spreadsheet where the source data format is different from target, and where you have fixed formulas in the target which you always will need.

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.

How to substract two cells of x row on excel

I'm making an Excel sheet to keep track of some activities. The thing is that I have 2 cells that are date type; I want the third cell to subtract the them to get the time that the x person spent on the activity.
I know that if I type =A2-A1 it's going to give me what I want, but, since its going to be a big Excel sheet with lots of records, I don't want to input the same formula for each row just changing the row number.
Is there a way to make Excel detect the row that the user is inputing data in and then make the requested formula to get the time?
you can turn your data range into a table by highlighting the range and going to the insert tab and clicking table. Then when you type the formula into the first cell and click in the cells when selecting instead of typing it out, you will notice that it is using the column names instead, also it will automatically fill the column with the new formula. That would be my suggestion.

fix for moving rows in google-spredsheet breaks array formula

I have an array formula in google sheets for an entire column, e.g. the following formula in C1
ArrayFormula(A1:A+B1:B)
And there is data in columns A and B.
If I were to grab a row and move it to another location. As soon as I move it the respective value in column C of that row is pasted as hard value and breaks the entire array formula.
Is there a way around this?
Unfortunately, there is no simple way around it. With arrays, the formula is usually tied with the positioning of the values as results vary according to the position of each value in an array. Hence, moving anything will result in the distortion of the formula.
The only (simple) way around it is to move your values by the cut-copy-paste method instead of dragging the whole row around. OR (For a more robust but complex implementation) write a script for Custom Functions in your sheet which will perform the necessary calculations and will not be affected when you move the values as it takes inputs from cell positions that have been pre-defined in the script.
Workaround found.
I was doing a manual sort which changed the row of my ARRAYFORMULA(), but has the same consequence as drag-n-dropping that "special row".
You will have to work with two sheets however.
Suppose that in your original data sheet (sheet 1), your have data on two columns (A and B), and you want to use ARRAYFORMULA() on column C, like in your example.
Leave sheet 1 "as is", create another sheet (sheet 2) and in top left cell type this:
={A1:B}
In sheet 2's column C, one cell below top (to leave room for header), enter:
=ARRAYFORMULA(A2:A+B2:B)
Then you can sort data as you wish in sheet 1, and ARRAYFORMULA() will always work in sheet 2 👍